Created
July 21, 2011 18:24
-
-
Save tochiz/1097815 to your computer and use it in GitHub Desktop.
C code for post to twitter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// twitpost.c | |
// require liboauth and libtokyocabinet | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <oauth.h> | |
#include <tcutil.h> | |
int twitter_post(const char *owner, const char *text) { | |
const char *consumer_key = ""; | |
const char *consumer_secret = ""; | |
const char *access_token = ""; | |
const char *access_token_secret = ""; | |
const char *test_call_uri = "http://api.twitter.com/1/statuses/update.json"; | |
char *req_url = NULL; | |
char *postarg = NULL; | |
int argc = 2; | |
char argv_wark[512]; | |
char **argv = (char**) malloc(sizeof(char*) * 2); | |
argv[0] = strdup(test_call_uri); | |
snprintf(argv_wark, sizeof(argv_wark), "status=@user %s:%s", owner, text); | |
tcstrcututf(argv_wark, 140); | |
argv[1] = strdup(argv_wark); | |
req_url = oauth_sign_array2(&argc, &argv, &postarg, OA_HMAC, NULL, | |
consumer_key, consumer_secret, access_token, access_token_secret); | |
free(argv[1]); | |
free(argv[0]); | |
free(argv); | |
oauth_http_post2(req_url, postarg, "Expect: \r\n"); | |
return 0; | |
} | |
int main() { | |
twitter_post("hogehoge", "twitter post test."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment