使用twitCurl如何将参数传递给twitter URL

时间:2011-05-13 11:04:44

标签: twitter

我需要访问Twitter API以进行我正在进行的快速项目,并且不希望在学习API方面过于紧张,我认为twitCurl将是理想的解决方案。

目前,我需要做的就是获取Twitter用户的最新提及,twitCurl可以轻松完成并将所有oAuth内容纳入讨价还价。

但我现在想在调用API时使用'since_id'参数。我无法用twitCurl看到这样做,实际上似乎无法将参数传递给许多twitCurl次调用。我错过了什么,或者这是twitCurl严重缺乏的东西吗?

如果无法做到这一点,那么有人可以为Twitter API建议和替代C ++包装器。

感谢阅读。

1 个答案:

答案 0 :(得分:2)

我不想回答我自己的问题,但我已经修好了,以防其他人有同样的问题,我会在这里记录。

我修改了twitCurl代码以添加一个额外的参数,一个表示'since_id'的字符串。最后它真的很简单,我已经将更改提交给了twitCurl开发人员。如果您不能等待,这是我的变化差异:

Index: twitcurl.cpp 
=================================================================== 
--- twitcurl.cpp        (revision 25) 
+++ twitcurl.cpp        (working copy) 
@@ -474,19 +474,28 @@ 
 * 
 * @description: method to get mentions 
 * 
-* @input: none 
+* @input: sinceId - since_id in string format 
 * 
 * @output: true if GET is success, otherwise false. This does not 
check http 
 *          response by twitter. Use getLastWebResponse() for that. 
 * 
 *--*/ 
-bool twitCurl::mentionsGet() 
+bool twitCurl::mentionsGet( std::string sinceId ) 
 { 
     bool retVal = false; 
     if( isCurlInit() ) 
     { 
+        /* Prepare URL */ 
+        std::string buildUrl( "" ); 
+        buildUrl = twitterDefaults::TWITCURL_MENTIONS_URL; 
+        if( sinceId.length() ) 
+        { 
+ 
buildUrl.append( twitCurlDefaults::TWITCURL_SINCEID.c_str() ); 
+            buildUrl.append( sinceId.c_str() ); 
+        } 
+ 
         /* Perform GET */ 
-        retVal = 
performGet( twitterDefaults::TWITCURL_MENTIONS_URL ); 
+        retVal = performGet( buildUrl ); 
     } 
     return retVal; 
 } 
Index: twitcurl.h 
=================================================================== 
--- twitcurl.h  (revision 25) 
+++ twitcurl.h  (working copy) 
@@ -24,6 +24,7 @@ 
     const std::string TWITCURL_EXTENSIONFORMAT = ".xml"; 
     const std::string TWITCURL_TARGETSCREENNAME = "? 
target_screen_name="; 
     const std::string TWITCURL_TARGETUSERID = "?target_id="; 
+    const std::string TWITCURL_SINCEID = "?since_id="; 
 }; 
 /* Default twitter URLs */ 
@@ -123,7 +124,7 @@ 
     bool timelineFriendsGet(); 
     bool timelineUserGet( std::string userInfo = "" /* in */, bool 
isUserId = false /* in */ ); 
     bool featuredUsersGet(); 
-    bool mentionsGet(); 
+    bool mentionsGet( std::string sinceId = "" ); 
     /* Twitter user APIs */ 
     bool userGet( std::string& userInfo /* in */, bool isUserId = 
false /* in */ );