Example of a program that uses the TwitPic library.

Dependencies:   EthernetNetIf TwitPic mbed DNSResolver

Committer:
treebykooba
Date:
Mon Feb 28 02:04:26 2011 +0000
Revision:
1:44a07cd54a87
Parent:
0:4a6b01bf147d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
treebykooba 0:4a6b01bf147d 1 #include "TwitPic.h"
treebykooba 0:4a6b01bf147d 2
treebykooba 0:4a6b01bf147d 3 #define IMAGE_PATH "/local/image.jpg"
treebykooba 0:4a6b01bf147d 4
treebykooba 1:44a07cd54a87 5 //get an api key from twit.pic, put it below
treebykooba 1:44a07cd54a87 6 const char twitpic_api_key[] = "PUT_YOUR_TWITPIC_API_KEY_HERE";
treebykooba 0:4a6b01bf147d 7
treebykooba 0:4a6b01bf147d 8
treebykooba 1:44a07cd54a87 9 //twitter has a lot more keys you need. get all those and enter them below.
treebykooba 1:44a07cd54a87 10 const char consumer_key[] = "PUT_YOUR CONSUMER_KEY_HERE";
treebykooba 1:44a07cd54a87 11 const char consumer_secret[] = "PUT_YOUR_CONSUMER_SECRET_HERE";
treebykooba 1:44a07cd54a87 12
treebykooba 1:44a07cd54a87 13
treebykooba 1:44a07cd54a87 14 const char access_token[] = "PUT_YOUR_ACCESS_TOKEN_HERE";
treebykooba 1:44a07cd54a87 15 const char access_token_secret[] = "ACCESS_TOKEN_SECRET_HERE";
treebykooba 0:4a6b01bf147d 16
treebykooba 0:4a6b01bf147d 17 int main() {
treebykooba 0:4a6b01bf147d 18 TwitPic twitpic(twitpic_api_key,consumer_key,consumer_secret,access_token,access_token_secret);
treebykooba 0:4a6b01bf147d 19 LocalFileSystem local("local");
treebykooba 0:4a6b01bf147d 20 EthernetNetIf network;
treebykooba 0:4a6b01bf147d 21
treebykooba 0:4a6b01bf147d 22
treebykooba 0:4a6b01bf147d 23 printf("Setting up network...\n");
treebykooba 0:4a6b01bf147d 24 EthernetErr ethErr = network.setup();
treebykooba 0:4a6b01bf147d 25 if (ethErr) {
treebykooba 0:4a6b01bf147d 26 printf("Error %d in network setup.\n", ethErr);
treebykooba 0:4a6b01bf147d 27 return -1;
treebykooba 0:4a6b01bf147d 28 }
treebykooba 0:4a6b01bf147d 29 printf("Network Setup OK\n");
treebykooba 0:4a6b01bf147d 30
treebykooba 0:4a6b01bf147d 31 printf("Opening File...\n");
treebykooba 0:4a6b01bf147d 32 FILE *img = fopen(IMAGE_PATH, "r");
treebykooba 0:4a6b01bf147d 33 if (img == NULL) {
treebykooba 0:4a6b01bf147d 34 printf("Error in file open.\n");
treebykooba 0:4a6b01bf147d 35 return -1;
treebykooba 0:4a6b01bf147d 36 }
treebykooba 0:4a6b01bf147d 37 printf("File open.\n");
treebykooba 0:4a6b01bf147d 38
treebykooba 0:4a6b01bf147d 39 int ret = twitpic.uploadAndPost("What the what?", img);
treebykooba 0:4a6b01bf147d 40 if (ret < 0) {
treebykooba 0:4a6b01bf147d 41 printf("Twitpic upload failed with error %i",ret);
treebykooba 0:4a6b01bf147d 42 return ret;
treebykooba 0:4a6b01bf147d 43 }
treebykooba 0:4a6b01bf147d 44 return 0;
treebykooba 0:4a6b01bf147d 45 }