From 36b11989c21feab57daa31846533d1cb6725515b Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Tue, 16 Oct 2012 18:41:01 +0000 Subject: Updated Twitter to version 1.0.0.2: Revision: 16 Autor: seventh.adept Datum: Dienstag, 16. Oktober 2012 15:33:18 Meldung: forgot to bump the version in version.h to 1.0.0.2 Revision: 15 Autor: seventh.adept Datum: Dienstag, 16. Oktober 2012 15:03:41 Meldung: - Updated plugin to work with API v1.1 - Made an attempt to fix truncated retweets. My work around isn't pretty and can fail, if anyone wants to help give me a yell - added comments Revision: 14 Autor: seventh.adept Datum: Donnerstag, 7. Juni 2012 15:38:40 Meldung: fixed the "&" issue in tweets version bump 1.0.0.1 git-svn-id: http://svn.miranda-ng.org/main/trunk@1960 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Twitter/src/twitter.cpp | 91 +++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 12 deletions(-) (limited to 'protocols/Twitter/src/twitter.cpp') diff --git a/protocols/Twitter/src/twitter.cpp b/protocols/Twitter/src/twitter.cpp index b9a6c7242b..794959b328 100644 --- a/protocols/Twitter/src/twitter.cpp +++ b/protocols/Twitter/src/twitter.cpp @@ -78,7 +78,7 @@ static T retrieve(const js::object &o,const std::string &key,bool allow_null = f -twitter::twitter() : base_url_("https://twitter.com/") +twitter::twitter() : base_url_("https://api.twitter.com/1.1/") {} bool twitter::set_credentials(const std::string &username, const std::wstring &consumerKey, const std::wstring &consumerSecret, @@ -120,8 +120,53 @@ const std::string & twitter::get_base_url() const return base_url_; } +// this whole function is wrong i think. should be calling friends/ids, not followers +/*js::array twitter::buildFriendList() { + + INT_PTR friendCursor = -1; + js::array IDs; // an array for the userIDs. i dunno if js::array is the right thing to use..? + js::array masterIDs; // the list that contains all the users that the user follows + + std::vector friends; + + while (friendCursor != 0) { + http::response resp = slurp(base_url_ + "/1.1/followers/ids.json?cursor=" + friendCursor + "&screen_name=" + username_,http::get); + if(resp.code != 200) + throw bad_response(); + + const js::variant var = json::parse( resp.data.begin(),resp.data.end() ); // pull the data out of the http response + if(var->type() == typeid(js::object)) // make sure the parsed data is of type js::object (??) + { + const js::object &friendIDs = boost::any_cast(*var); // cast the object into the type we can use + if(friendIDs.find("error") != friendIDs.end()) // don't really know why error should be at the end here? + throw std::exception("error while parsing friendIDs object from ids.json"); + + // ok need to find out how to convert all the IDs into an array. dunno if i can magically make it happen, or + // if i will have to parse it myself and add them one by one :( + IDs = retrieve(friendIDs,"ids"); + for(js::array::const_iterator i=IDs.begin(); i!=IDs.end(); ++i) { + //LOG("friends ID: " + i); + // add array to master array + js::object one = boost::any_cast(**i); + masterIDs.push_back(one); // i don't understand this. how do we push into the array? should i just use C++ arrays (list?) and bail on boost? + } + + // now we need to pick out the cursor stuff, and keep punching IDs into the array + } + else { + throw std::exception("in buildFriendList(), return type is not js::object"); + } + } + + +}*/ + + std::vector twitter::get_friends() { + // maybe once i have the buildFriendLIst() func working.. but for now let's just get twitter working. + //js::array friendArray = buildFriendList(); + std::vector friends; http::response resp = slurp(base_url_+"statuses/friends.json",http::get); @@ -304,23 +349,45 @@ std::vector twitter::get_statuses(int count,twitter_id id) { const js::object &one = boost::any_cast(**i); const js::object &user = retrieve(one,"user"); + //size_t RTcount = retrieve(one,"retweet_count", true); // why doesn't this work?? it can't cast the output into an int even though twitter api says it's an int twitter_user u; u.username = retrieve(user,"screen_name"); - bool isTruncated = retrieve(one,"truncated"); - - if (isTruncated) { // the tweet will be truncated unless we take action. i hate you twitter API - // here we grab the "retweeted_status" um.. section? it's in here that all the info we need is - const js::object &Retweet = retrieve(one,"retweeted_status"); - const js::object &RTUser = retrieve(Retweet,"user"); - - std::string retweeteesName = retrieve(RTUser,"screen_name"); // the user that is being retweeted - std::string retweetText = retrieve(Retweet,"text"); // their tweet in all it's untruncated glory - u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand + std::string rawText = retrieve(one,"text"); + if (rawText.length() == 140) { // might be a truncated tweet + if (rawText.substr(0, 4) == "RT @") { // starting to look like a RT... + if (rawText.substr(136, 4) == " ...") { // ok this is the best I can do. it starts with "RT @", ends with " ...", and is the full 140 chars + + + //if (RTcount > 0) { // the tweet will be truncated unless we take action. i hate you twitter API + //MessageBox(NULL, L"retweeted: TRUE", L"long tweets", MB_OK); + // here we grab the "retweeted_status" um.. section? it's in here that all the info we need is + // at this point the user will get no tweets and an error popup if the tweet happens to be exactly 140 chars, start with + // "RT @", end in " ...", and notactually be a real retweet. it's possible but unlikely, wish i knew how to get + // the retweet_count variable to work :( + const js::object &Retweet = retrieve(one,"retweeted_status"); + const js::object &RTUser = retrieve(Retweet,"user"); + + std::string retweeteesName = retrieve(RTUser,"screen_name"); // the user that is being retweeted + std::string retweetText = retrieve(Retweet,"text"); // their tweet in all it's untruncated glory + u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand + } + } } else { // if it's not truncated, then the twitter API returns the native RT correctly anyway, - u.status.text = retrieve(one,"text"); // so we can just pretend it doesn't happen + + //std::string twt = retrieve(one,"text"); // no need to do this anymore, we already grabbed it above in rawText + + // ok here i'm trying some way to fix all the "&" things that are showing up + // i dunno why it's happening, so i'll just find and replace each occurance :/ + size_t pos = 0; + while((pos = rawText.find("&", pos)) != std::string::npos) { + rawText.replace(pos, 5, "&"); + pos += 1; + } + + u.status.text = rawText; // so we can just pretend it doesn't happen } u.status.id = retrieve(one,"id"); -- cgit v1.2.3