ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • twit4cpp - 트위터 Twitter API : 타임라인(Timeline) 가져오기 예제
    Programming/twitterAPI 2010. 11. 8. 22:24
    반응형
    [Programming/twit4cpp] - twit4cpp - Twitter API : XAuth 인증 예제
    [Programming/twit4cpp] - twit4cpp - Twitter API : OAuth 인증 예제
    [Programming/twit4cpp] - twit4cpp - 트위터 Twitter API : 다이렉트메시지(DirectMessages) 예제


    #include <twit/Twitter.h>
    #include <stdio.h>
    
    #if defined(WIN32)||defined(_WIN32)
    #  if _DEBUG
    #     pragma comment(lib,"../../../lib/twit4cppd.lib")
    #  else
    #     pragma comment(lib, "../../lib/twit4cpp.lib")
    #  endif
    #endif
    
    using namespace std;
    using namespace Twit;
    int main(int argc, char* argv[])
    {
       /* twit4cpp Sample Application */
       try
       {
          string
             customerKey("2rBtCAh5o10zMlS2FbRYAA"),
             customerSecert("MoZvHvDGbi6zoPu6Q1SZHsalGynP8qWt9dlB1NKlvQg");
    
    	  string
    		  aToken("access token"),
    		  aSecret("access token secret");
    
          Twitter twit(customerKey, customerSecert);
    	  twit.setAccessToken(aToken, aSecret);
          
    	  Resource::CTimeline& tl = twit.Timeline;
    	  
         /***
          *	Public Timeline
          */
         puts("Public Timeline -----------------------------------------");
    	  Value::Statuses val = tl.PublicTimeline.get();
    	  for(size_t i=0; i<val.size(); i++)
    	  {
    		  Value::Status& status = val[i];
    		  printf("username : %s\n", status.getUser()->getScreenName().c_str());
    		  wprintf(L"text : %s\n", status.getText().c_str());
    		  printf("---------------------------------------------\n");
    		  //MessageBoxW(0,status.getText().c_str(),L"text",0);
    	  }
    
         /***
          *	Friends Timeline
          */
         puts("Friends Timeline -----------------------------------------");
    	  if( tl.FriendsTimeline.request() )
    	  {
    		  val = tl.FriendsTimeline.value();
    		  for(size_t i=0; i<val.size(); i++)
    		  {
    			  Value::Status& status = val[i];
    			  printf("username : %s\n", status.getUser()->getScreenName().c_str());
    			  wprintf(L"text : %s\n", status.getText().c_str());
    			  printf("---------------------------------------------\n");
    		  }
    	  }
    	  else
    	  {
    		  const Error& e = tl.FriendsTimeline.getError();
    		  printf("error message : %s\n", e.getMessage().c_str());
    	  }
    
         /***
          *	Home Timeline
          */
         puts("Home Timeline -----------------------------------------");
    	  val = tl.HomeTimeline.get();
    	  for(size_t i=0; i<val.size(); i++)
    	  {
    		  Value::Status& status = val[i];
    		  printf("username : %s\n", status.getUser()->getScreenName().c_str());
    		  wprintf(L"text : %s\n", status.getText().c_str());
    		  printf("---------------------------------------------\n");
    	  }
    
         /***
          *	User Timeline
          */
         puts("User Timeline -----------------------------------------");
         val = tl.UserTimeline.get();
    	  for(size_t i=0; i<val.size(); i++)
    	  {
    		  Value::Status& status = val[i];
    		  printf("username : %s\n", status.getUser()->getScreenName().c_str());
    		  wprintf(L"text : %s\n", status.getText().c_str());
    		  printf("---------------------------------------------\n");
    	  }
    
         /***
          *	Mentions
          */
         puts("Mentions -----------------------------------------");
         val = tl.Mentions.get();
         for(size_t i=0; i<val.size(); i++)
         {
            Value::Status& status = val[i];
            printf("username : %s\n", status.getUser()->getScreenName().c_str());
            wprintf(L"text : %s\n", status.getText().c_str());
            printf("---------------------------------------------\n");
         }
    
         /***
          *	Retweeted By Me
          */
         puts("Retweeted By Me -----------------------------------------");
         val = tl.RetweetedByMe.get();
         for(size_t i=0; i<val.size(); i++)
         {
            Value::Status& status = val[i];
            printf("username : %s\n", status.getUser()->getScreenName().c_str());
            wprintf(L"text : %s\n", status.getText().c_str());
            printf("---------------------------------------------\n");
         }
    
         /***
          *	Retweeted To Me
          */
         puts("Retweeted To Me -----------------------------------------");
         val = tl.RetweetedToMe.get();
         for(size_t i=0; i<val.size(); i++)
         {
            Value::Status& status = val[i];
            printf("username : %s\n", status.getUser()->getScreenName().c_str());
            wprintf(L"text : %s\n", status.getText().c_str());
            printf("---------------------------------------------\n");
         }
    
         /***
          *	Retweets Of Me
          */
         puts("Retweets Of Me -----------------------------------------");
         val = tl.RetweetsOfMe.get();
         for(size_t i=0; i<val.size(); i++)
         {
            Value::Status& status = val[i];
            printf("username : %s\n", status.getUser()->getScreenName().c_str());
            wprintf(L"text : %s\n", status.getText().c_str());
            printf("---------------------------------------------\n");
         }
       }
       catch(const Error& e)
       {
          printf("code : %d\n", e.getCode());
          printf("message : %s\n", e.getMessage().c_str());
       }   
    	return 0;
    }
    

    * twit4cpp source & sample


    반응형

    TAG

    댓글 0

Designed by Tistory.