diff --git a/backends/twitter/TwitterResponseParser.cpp b/backends/twitter/TwitterResponseParser.cpp index 2e403da6..350f25c8 100644 --- a/backends/twitter/TwitterResponseParser.cpp +++ b/backends/twitter/TwitterResponseParser.cpp @@ -52,7 +52,6 @@ std::vector getTimeline(std::string &xml) const std::string xmlns = rootElement->getNamespace(); const std::vector children = rootElement->getChildren(TwitterReponseTypes::status, xmlns); -// const std::vector::iterator it; for(int i = 0; i < children.size() ; i++) { const Swift::ParserElement::ref status = children[i]; @@ -61,6 +60,26 @@ std::vector getTimeline(std::string &xml) return statuses; } +std::vector getUsers(std::string &xml) +{ + std::vector users; + Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + + if(rootElement->getName() != TwitterReponseTypes::users) { + LOG4CXX_ERROR(logger, "XML doesn't correspond to user list") + return users; + } + + const std::string xmlns = rootElement->getNamespace(); + const std::vector children = rootElement->getChildren(TwitterReponseTypes::user, xmlns); + + for(int i = 0 ; i < children.size() ; i++) { + const Swift::ParserElement::ref user = children[i]; + users.push_back(getUser(user, xmlns)); + } + return users; +} + std::vector getIDs(std::string &xml) { std::vector IDs; diff --git a/backends/twitter/TwitterResponseParser.h b/backends/twitter/TwitterResponseParser.h index 6339d0e1..c1e61b06 100644 --- a/backends/twitter/TwitterResponseParser.h +++ b/backends/twitter/TwitterResponseParser.h @@ -23,6 +23,7 @@ namespace TwitterReponseTypes const std::string favorited = "favorited"; const std::string retweeted = "retweeted"; const std::string user = "user"; + const std::string users = "users"; const std::string status = "status"; }; @@ -96,6 +97,7 @@ class Status std::vector getTimeline(std::string &xml); std::vector getIDs(std::string &xml); +std::vector getUsers(std::string &xml); Status getStatus(const Swift::ParserElement::ref &element, const std::string xmlns); User getUser(const Swift::ParserElement::ref &element, const std::string xmlns); #endif diff --git a/backends/twitter/libtwitcurl/twitcurl.cpp b/backends/twitter/libtwitcurl/twitcurl.cpp index f50f5c6b..e556c9b3 100644 --- a/backends/twitter/libtwitcurl/twitcurl.cpp +++ b/backends/twitter/libtwitcurl/twitcurl.cpp @@ -584,6 +584,39 @@ bool twitCurl::userGet( std::string& userInfo, bool isUserId ) return retVal; } +/*++ +* @method: twitCurl::userLookup +* +* @description: method to get a number of user's profiles +* +* @input: userInfo - vector of screen names or user ids +* isUserId - true if userInfo contains an id +* +* @output: true if POST is success, otherwise false. This does not check http +* response by twitter. Use getLastWebResponse() for that. +* +*--*/ +bool twitCurl::userLookup( std::vector &userInfo, bool isUserId ) +{ + bool retVal = false; + if( userInfo.size() ) + { + std::string userIds = isUserId?twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME; + std::string sep = ""; + for(int i=0 ; i +#include +#include #include #include #include "oauthlib.h" @@ -69,6 +71,7 @@ namespace twitterDefaults const std::string TWITCURL_USERTIMELINE_URL = "http://api.twitter.com/1/statuses/user_timeline"; /* Users URLs */ + const std::string TWITCURL_LOOKUPUSERS_URL = "http://api.twitter.com/1/users/lookup"; const std::string TWITCURL_SHOWUSERS_URL = "http://api.twitter.com/1/users/show"; const std::string TWITCURL_SHOWFRIENDS_URL = "http://api.twitter.com/1/statuses/friends"; const std::string TWITCURL_SHOWFOLLOWERS_URL = "http://api.twitter.com/1/statuses/followers"; @@ -154,6 +157,7 @@ public: bool mentionsGet( std::string sinceId = "" /* in */ ); /* Twitter user APIs */ + bool userLookup( std::vector &userInfo /* in */, bool isUserId = false /* in */); bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ ); bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ ); bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ ); diff --git a/backends/twitter/main.cpp b/backends/twitter/main.cpp index 9abf8965..6899b3be 100644 --- a/backends/twitter/main.cpp +++ b/backends/twitter/main.cpp @@ -166,7 +166,7 @@ class TwitterPlugin : public NetworkPlugin { void handlePINExchange(const std::string &user, std::string &data) { sessions[user]->getOAuth().setOAuthPin( data ); if (sessions[user]->oAuthAccessToken() == false) { - LOG4CXX_ERROR(logger, "Error while exchanging PIN for Access Token!") + LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!") handleLogoutRequest(user, ""); return; } @@ -186,7 +186,7 @@ class TwitterPlugin : public NetworkPlugin { storagebackend->updateUserSetting((long)info.id, OAUTH_SECRET, OAuthAccessTokenSecret); connectionState[user] = CONNECTED; - LOG4CXX_INFO(logger, "Sent PIN " << data << " and obtained Access Token"); + LOG4CXX_INFO(logger, user << ": Sent PIN " << data << " and obtained Access Token"); } void printHelpMessage(const std::string &user) { @@ -203,11 +203,11 @@ class TwitterPlugin : public NetworkPlugin { void handleDirectMessage(const std::string &user, std::string &username, std::string &data) { if(sessions[user]->directMessageSend(username, data, false) == false) { - LOG4CXX_ERROR(logger, "Error while sending directed message to user " << username ); + LOG4CXX_ERROR(logger, user << ": Error while sending directed message to user " << username ); return; } - LOG4CXX_INFO(logger, "Sending " << data << " to " << username) + LOG4CXX_INFO(logger, user << ": Sending " << data << " to " << username) std::string replyMsg; sessions[user]->getLastWebResponse( replyMsg ); @@ -226,10 +226,10 @@ class TwitterPlugin : public NetworkPlugin { while(replyMsg.length() == 0) { sessions[user]->getLastWebResponse( replyMsg ); } - LOG4CXX_INFO(logger, "twitCurl:statusUpdate web response: " << replyMsg ); + LOG4CXX_INFO(logger, user << ": twitCurl:statusUpdate web response: " << replyMsg ); } else { sessions[user]->getLastCurlError( replyMsg ); - LOG4CXX_INFO(logger, "twitCurl::statusUpdate error: " << replyMsg ); + LOG4CXX_INFO(logger, user << ": twitCurl::statusUpdate error: " << replyMsg ); } LOG4CXX_INFO(logger, "Updated status for " << user << ": " << data); } @@ -247,7 +247,7 @@ class TwitterPlugin : public NetworkPlugin { sessions[user]->getLastWebResponse( replyMsg ); } - LOG4CXX_INFO(logger, "twitCurl::timeline web response: " << replyMsg.length() << " " << replyMsg << "\n" ); + LOG4CXX_INFO(logger, user << ": twitCurl::timeline web response: " << replyMsg.length() << " " << replyMsg << "\n" ); std::vector tweets = getTimeline(replyMsg); std::string timeline = "\n"; @@ -259,7 +259,7 @@ class TwitterPlugin : public NetworkPlugin { } else { sessions[user]->getLastCurlError( replyMsg ); - LOG4CXX_INFO(logger, "twitCurl::timeline error: " << replyMsg ); + LOG4CXX_INFO(logger, user << ": twitCurl::timeline error: " << replyMsg ); } } @@ -276,24 +276,29 @@ class TwitterPlugin : public NetworkPlugin { sessions[user]->getLastWebResponse( replyMsg ); } - LOG4CXX_INFO(logger, "twitCurl::friendsIdsGet web response: " << replyMsg.length() << " " << replyMsg << "\n" ); + LOG4CXX_INFO(logger, user << ": twitCurl::friendsIdsGet web response: " << replyMsg.length() << " " << replyMsg << "\n" ); std::vector IDs = getIDs( replyMsg ); - for(int i=0 ; i tweets = getTimeline(replyMsg); - std::string timeline = "\n"; - for(int i=0 ; iuserLookup(IDs, true); + sessions[user]->getLastWebResponse( replyMsg ); + LOG4CXX_INFO(logger, user << ": twitCurl::UserLookUp web response: " << replyMsg.length() << " " << replyMsg << "\n" ); - handleMessage(user, "twitter-account", timeline);*/ + std::vector users = getUsers( replyMsg ); + + std::string userlist = "\n***************USER LIST****************\n"; + for(int i=0 ; i < users.size() ; i++) { + userlist += "*)" + users[i].getUserName() + " (" + users[i].getScreenName() + ")\n"; + } + userlist += "***************************************\n"; + handleMessage(user, "twitter-account", userlist); } else { sessions[user]->getLastCurlError( replyMsg ); - LOG4CXX_INFO(logger, "twitCurl::friendsIdsGet error: " << replyMsg ); + LOG4CXX_INFO(logger, user << ": twitCurl::friendsIdsGet error: " << replyMsg ); } }