Anyone help me out with libcurl please (Not linking Errors)

Am trying to login to my facebook and post somthing on my wall.
When i check for error with curl_easy_strerror() i dont get any when runing recuests.

Can someone please help me understand what am doing wrong?
An example is also wery welcome at this point.

Here is my code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "includes.h"

int main ()
{
    curl_global_init( CURL_GLOBAL_ALL );
    CURL * h_curl = curl_easy_init();
    CURLcode result;

    static string buffer;
    static char errorBuffer[CURL_ERROR_SIZE];
    cout << "===========\n\t================" << endl;
    if (h_curl)
    {
        // Tilkoblings Innstilinger  -  CURL * h_curl; .
        curl_easy_setopt(h_curl, CURLOPT_ERRORBUFFER, errorBuffer);     // Pass a char * to a buffer that the libcurl may store human readable error messages in
        curl_easy_setopt(h_curl, CURLOPT_URL, "https://facebook.com/login.php/");   // URL to connect to...
        curl_easy_setopt(h_curl, CURLOPT_HEADER, 0);                    // A parameter set to 1 tells the library to include the header in the body output.
        curl_easy_setopt(h_curl, CURLOPT_FOLLOWLOCATION, 1);            // A parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header.
        curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION, writer);        // Pass a pointer to a function that matches the following prototype: writer()
        curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, &buffer);           // Data pointer to pass to the file write function. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you'll get as input.
        curl_easy_setopt(h_curl, CURLOPT_SSL_VERIFYPEER, 0L);            // This option determines whether curl verifies the authenticity of the peer's certificate. A value of 1 means curl verifies; 0 (zero) means it doesn't.
        curl_easy_setopt(h_curl, CURLOPT_SSL_VERIFYHOST, 2);            // This option determines whether libcurl verifies that the server cert is for the server it is known as.
        curl_easy_setopt(h_curl, CURLOPT_VERBOSE, 1);                   // Set the parameter to 1 to get the library to display a lot of verbose information about its operations.
        curl_easy_setopt(h_curl, CURLOPT_USERAGENT, "Mozila/4.0" );     // Set Browser header for client.
        curl_easy_setopt(h_curl, CURLOPT_COOKIEFILE, "");

        result = curl_easy_perform(h_curl);

        if (result == CURLE_OK)
        {
            // Allt gikk fint printer buffer til skjerm
            // cout << buffer << endl;
            cout << "\nBytes Read: " << buffer.size() << endl;
        } else {
                cout << "CURL Error: " << result << endl;
                cout << curl_easy_strerror(result) << endl << endl;
                system("PAUSE");
                return 0;
            }

    }

    cout << "===========\n\t================" << endl;
    string FaceLogInForm = "email=mymail@hotmail.no&pass=Pass123";
    curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, FaceLogInForm.c_str() );
    result = curl_easy_perform( h_curl);

    if (result == CURLE_OK)
    {
        cout << "Loging in to Facebook\t\t\t[OK]" << endl;
    } else {
        cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
        }

    curl_easy_setopt(h_curl, CURLOPT_URL, "http://www.facebook.com/?ref=tn_tnmn/");

    result = curl_easy_perform(h_curl);
    if (result == CURLE_OK )
    {
        cout << "Continuing...\t\t\t[OK]" << endl;
    } else {
        cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
        }

    cout << "===========\n\t================" << endl;
    string PostComment = "xhpc_message_text=Testing from app.&xhpc_message=Testing from app.";
    curl_easy_setopt(h_curl, CURLOPT_URL, "http://www.facebook.com/ajax/updatestatus.php/");
    curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, PostComment.c_str() );
    result = curl_easy_perform( h_curl );

    if (result == CURLE_OK)
    {
        cout << "Sucessfully Posted Comment on wall. " << endl;
    } else {
        cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
        }

    curl_easy_cleanup(h_curl);

    curl_global_cleanup();

    cout << "===========\n\t================" << endl;
    system("PAUSE");
    return 0;
}

static int writer(char *data,
                  size_t size, size_t nmemb,
                  string *buffer )
{
    int result = 0;

    // Er det noe i bufferen montro?
    if (buffer != NULL)
    {
        buffer->append( data, (size * nmemb) );
        result = size * nmemb;
    }
    return result;
}



Any help on this is much aprichiated.

Cheers
WetCode
Last edited on
Dont anyone have a pointer in the correct direction i whould realy aprichiat it.
Am totoly lost on what to do here and way am not geting the post to show up..
Thanks for reading..

WetCode
Last edited on
Since nobody seems to know libcurl is there a other library i can use for this cross platform if possibol
Thanks
Unless I'm mistaken, with each request you need to pass the cookies to libcurl, in case the server responded with a cookie update in a previous request. I'm not sure if libcurl performs this update automatically.

Rather than performing the login procedure, wouldn't it be easier to copy the cookies from your browser and pass them to libcurl? It should work as long as F***book doesn't timeout sessions.
I realy want it to do everything. Am prety shure i can define a Cookiehainlist that libcurl can use.
Like the read and write function and then give libcurl the buffer when ever it needs a cookie.
Thanks for the reply much aprichiated :)

Cheers
Watru
Oh, one thing I forgot to mention is that, assuming what I said previously was true, you would need to get the cookie updates from the response.
Libcurl re-uses session cookies automatically by default. Be aware that Facebook uses Javascript, it could send cookies by javascript too, libcurl cannot understand javascipt for you.

You could try to use a mobile user-agent and try to reverse engineer the mobile version of Facebook, it could be much simpler to use.
I have thot of the Java responses and i was thinking JSONcpp library for that.
Tho i dont know anything about it other then it supports code convertion from Java, C++, Phyton and a couple of others.

But i think all the mobil apps are writen in Java (I Think).
I don't really understand your reply ...

I told you to use http://m.facebook.com/ as URL within libcurl, as it could be much easier to parse the response and do what you want.
Ok i dont know how i whould reverse enginere a mobile app.
What i mean is that i have found a library on Google that can convert
Java to C++ I dont know how this work but i think it thos what I need it for i have not yet started reding up on this library.

Am currently geting contorbal with libcurl..

Here is a link to the library am talking about please correct me if am wrong.
http://jsoncpp.sourceforge.net/

EDIT: I dident notice the link before now. m.facebook.com/ . I feel stupid . Thanks never struck my mind ;)

Cheers
WetCode
Last edited on
Topic archived. No new replies allowed.