2011-05-13 87 views
1

我需要访问Twitter API以进行一个快速项目,我正在研究并且不希望太紧张地学习API我认为twitCurl将是理想的解决方案。使用twitCurl如何将参数传递给Twitter网址

目前,我所需要做的就是获取Twitter用户的最新提及,其中twitCurl可以非常轻松地完成,并将所有oAuth的东西用于讨价还价。

但我现在想在我调用API时使用'since_id'参数。我看不到用twitCurl来做到这一点,实际上似乎没有办法将参数传递给许多twitCurl调用。我是否错过了一些东西,或者这是从twitCurl严重缺乏的东西?

如果这是不可能的,那么可以有人建议和替代Twitter API的C++包装。

感谢您的阅读。

回答

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 */);