コード例 #1
0
ファイル: libgsocial.c プロジェクト: techlover/vitweet
char *gsocial_get_twitter_authorize_url()
{
    int verifier;
    char line[100];
    char *req_url;
    char *reply;
    char ath_uri[90];
    char *new_reply;
    char *twitter_auth_url;

    req_url = oauth_sign_url2(request_token_uri, NULL, OA_HMAC, NULL,
            consumer_key, consumer_secret, NULL, NULL);
    //printf("%s\n", req_url);

    reply = oauth_http_get(req_url, NULL);
    //printf("%s\n", reply);
    if(gsocial_parse_reply_access(reply, &req_key, &req_secret))
        printf("Something is wrong!\n");

    free(reply);

    //fprintf(stdout, "%s%s\nPIN: ", twitter_authorize_uri, req_key);

    twitter_auth_url = g_strconcat(twitter_authorize_uri, req_key, NULL);
    //g_print(twitter_auth_url);

    return twitter_auth_url;
}
コード例 #2
0
ファイル: tweetd.c プロジェクト: JAORMX/TweetRemoteControl
/*
 * Read the key and the secret key and set the variables to 
 * those values.
 */
static void read_keys(char **key, char **secret)
{
    gchar *filename, *content;
    gchar *path;
    gsize bytes;

    GError *error = NULL;

    filename = g_build_filename (g_get_current_dir(), "keys", NULL);

    content = NULL;

    if(!g_file_test (filename, G_FILE_TEST_EXISTS)) {
        path = g_build_path ("/", "/etc/", "tweetd/", NULL);
        filename = g_build_filename (path, "keys", NULL);
    }

    if(!g_file_test (filename, G_FILE_TEST_EXISTS)) {
        g_mkdir(path, 0700);
        fprintf(stdout,
                "Please open the following link in your browser, and "
                "allow 'tweetd' to access your account. Then paste "
                "back the provided PIN in here.\n");

        gchar *url = gsocial_get_twitter_authorize_url();
        printf ( "%s\n", url );
        fprintf(stdout, "PIN: ");
        char *pin= get_string_from_stdin();
        content = gsocial_get_access_key_full_reply(pin);
        if(content)
            g_file_set_contents(filename, content, strlen(content), &error);
        else {
            g_error("PIN not entered");
        }
    }

    g_file_get_contents(filename, &content, &bytes, &error);

    if(gsocial_parse_reply_access(content, key, secret))
        g_error("Error: Can't read file");

    g_free(content);
    g_free(filename);

}