Changeset 508c340 for protocols


Ignore:
Timestamp:
2010-04-26T00:42:37Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
acba168
Parents:
b2bc25c
Message:

Successfully posted a tweet!

Twitter's tricky. It returns vars (user_id, screen_name) in the access token
that, the way I read the spec, should be included in all subsequent queries.
However, stuff only started to work when I dropped those vars.

This code's definitely not pretty ATM. Need to clean up now that it actually
works.

Location:
protocols/twitter
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rb2bc25c r508c340  
    8282
    8383        td->user = acc->user;
    84         td->pass = acc->pass;
     84        if( strstr( acc->pass, "oauth_token=" ) == NULL )
     85                td->pass = g_strdup( acc->pass );
     86        else
     87                td->oauth = g_strdup( acc->pass );
    8588        td->home_timeline_id = 0;
    8689
     
    119122        if( td )
    120123        {
     124                g_free( td->pass );
     125                g_free( td->oauth );
    121126                g_free( td );
    122127        }
  • protocols/twitter/twitter.h

    rb2bc25c r508c340  
    3737        char* user;
    3838        char* pass;
     39        char* oauth;
    3940        guint64 home_timeline_id;
    4041        gint main_loop_id;
  • protocols/twitter/twitter_http.c

    rb2bc25c r508c340  
    3535#include "misc.h"
    3636#include "base64.h"
     37#include "oauth.h"
    3738#include <ctype.h>
    3839#include <errno.h>
     
    4546 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c
    4647 */
    47 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char** arguments, int arguments_len)
     48void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char* oauth_token, char** arguments, int arguments_len)
    4849{
    4950        url_t *url = g_new0( url_t, 1 );
     
    110111
    111112        // If a pass and user are given we append them to the request.
    112         if (userpass_base64)
     113        if (oauth_token)
     114        {
     115                char *full_header;
     116               
     117                full_header = oauth_http_header(oauth_token,
     118                                                is_post ? "POST" : "GET",
     119                                                url_string, url_arguments);
     120               
     121                tmp = g_strdup_printf("%sAuthorization: %s\r\n", request, full_header);
     122                g_free(request);
     123                g_free(full_header);
     124                request = tmp;
     125        }
     126        else if (userpass_base64)
    113127        {
    114128                tmp = g_strdup_printf("%sAuthorization: Basic %s\r\n", request, userpass_base64);
  • protocols/twitter/twitter_http.h

    rb2bc25c r508c340  
    2929
    3030void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post,
    31                                         char* user, char* pass, char** arguments, int arguments_len);
     31                   char* user, char* pass, char *oauth_token, char** arguments, int arguments_len);
    3232
    3333#endif //_TWITTER_HTTP_H
  • protocols/twitter/twitter_lib.c

    rb2bc25c r508c340  
    130130        args[0] = "cursor";
    131131        args[1] = g_strdup_printf ("%d", next_cursor);
    132         twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, args, 2);
     132        twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth, args, 2);
    133133
    134134        g_free(args[1]);
     
    396396        }
    397397
    398         twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, args, td->home_timeline_id ? 4 : 2);
     398        twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth, args, td->home_timeline_id ? 4 : 2);
    399399
    400400        g_free(args[1]);
     
    620620        args[1] = g_strdup_printf ("%d", next_cursor);
    621621
    622         twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, args, 2);
     622        twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth, args, 2);
    623623
    624624        g_free(args[1]);
     
    654654        args[0] = "status";
    655655        args[1] = msg;
    656         twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, args, 2);
     656        twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 2);
    657657//      g_free(args[1]);
    658658}
     
    672672        args[3] = msg;
    673673        // Use the same callback as for twitter_post_status, since it does basically the same.
    674         twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, args, 4);
     674        twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 4);
    675675//      g_free(args[1]);
    676676//      g_free(args[3]);
Note: See TracChangeset for help on using the changeset viewer.