Noticed that the search query combo like "#hashtag from:username" doesn't work any longer. Seems that the twitter class php is still using the old http://search.twitter.com/search.json?q= and still using API 1 for username statuses and favorites feed. Upon checking the code I though it was as easy as replacing endpoints but seems that there has to be some tweaks with authentication as well which is connected to twitter drupal module. Will appreciate any help thanks guys!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kilowattz created an issue. See original summary.

sachin.bansal’s picture

FileSize
433 bytes

Hi,

Twitter pull module is compatible with Twitter module but authenticated account should be added on twitter module settings page from which tweets have to be fetched.

To fetch tweets of any account, please apply attached patch and then you just need to add one authenticated account on twitter settings page.

Thanks.

joachim’s picture

Issue tags: -API, -twitter

I'm not sure how the patch relates to the issue summary...

kilowattz’s picture

Hi Sachin,

I do understand the setup between the Twitter and Twitter Pull module. My real concern is that the old twitter search API endpoint (which is being used in twitter pull module) has been deprecated and needs to be updated. I am having some difficulties understanding the new way of calling the search api. Hope this clears it up.

msherron’s picture

I've rolled a patch that uses the Twitter modules' auth_call function to make authenticated requests to the new API. I've also updated the endpoint paths to use the new 1.1 APIs. Since the old APIs are deprecated, I've collapsed get_items and twitter_get_items into one function.

msherron’s picture

msherron’s picture

Status: Active » Needs review
msherron’s picture

Uploading a new patch with format-patch git attrib info.

msherron’s picture

joachim’s picture

Status: Needs review » Needs work

Thanks for the patch!

It does need a little more work though:

  1. +++ b/twitter_pull.class.inc
    @@ -2,7 +2,7 @@
    - * twitter pull class implementation
    + * Twitter pull class implementation
    
    @@ -41,78 +41,13 @@ class twitter_puller {
    -   * Use the twitter module to get the results.
    +   * Use the Twitter module to get the results.
        *
    -   *  - The twitter module will use an authenticated session to get the tweets
    -   *  - via the twiter 1.1 API.
    +   *  - The Twitter module will use an authenticated session to get the tweets
    +   *  - via the Twitter 1.1 API.
    
    @@ -127,22 +62,27 @@ class twitter_puller {
    -    // Determin the type of request.
    ...
    +    // Determine the type of request.
    

    ... or in this case, less work!

    Please resist the urge to clean up the typos. I know they're annoying and it's so easy to fix them on your way past, but it makes patches much harder to understand and review!

    (I'll happily take a follow-up patch that cleans those up after this is in.)

  2. +++ b/twitter_pull.class.inc
    @@ -127,22 +62,27 @@ class twitter_puller {
    +    $force = TRUE;
    

    What's the point of setting this as a variable? I presume it's an optional parameter to twitter_connect()?

  3. +++ b/twitter_pull.class.inc
    @@ -162,33 +102,33 @@ class twitter_puller {
    -    // Try to load the status via the twitter api (from the twitter module).
    -    $result = $twitter->call($path, $params, "GET");
    +    // Try to load the status via the Twitter REST api.
    +    $result = json_decode($twitter->auth_request($path, $params, "GET"));
     
         // Create/Empty the tweets array.
         $this->tweets = array();
     
         // Search results return metadata and the rusults in a sub-array
         // We need to parse the actual result array.
    -    $result = isset($result['statuses']) ? $result['statuses'] : $result;
    +    $result = isset($result->statuses) ? $result->statuses : $result;
     
    

    I don't follow this change. Has there been a change to Twitter module's API, as well as the twitter.com's API?

msherron’s picture

Status: Needs work » Needs review
FileSize
6.83 KB

Ok, I've removed all typo fixes except for ones where I was directly adding new comments.

What's the point of setting this as a variable? I presume it's an optional parameter to twitter_connect()?

Yes. I'm modeling this work after Twitter modules' drush_twitter_search() since we're doing very similar work here in twitter_pull. The $force parameter is meant to load tweets to accounts that are not either global accounts (honestly not sure what that means) or that you've previously authenticated via OAuth. The new Twitter 1.1 API allows you to pull tweets from accounts other than yours, so long as you're authenticated with at least one active Twitter account.

I had previously set a variable because I thought in some cases setting $force to true wouldn't be necessary, but I found in my testing that it was always necessary. I've removed the variable (since it never changes) and just always send TRUE in the function call. Thanks for pointing that out.

I don't follow this change. Has there been a change to Twitter module's API, as well as the twitter.com's API?

Yes. The 1.1 API requires OAuth, and Twitter has deprecated non-authenticated requests to the old 1.0 endpoints. Also, all endpoints return data in json, thus the json_decode and subsequent data structure changes.

rodrigoaguilera’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.x-dev
FileSize
6.46 KB

Same patch as 11 but without the git info in the header so it can be applied with other tools other than git.