Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We updated to Twitter 5.9 and all Twitter Pulls broke giving us 3 errors:
Could not retrieve data from Twitter. Forbidden
Twitter Pull is using an Unauthenticated request to twitter apis. Download, enable and configure the twitter module to allow for authenticated requests.
There are no authenticated Twitter accounts to use for API connections.
Once we reverted back to Twitter 5.8 all Twitter Pulls came back with no errors.
So I think it is safe to say something has changed in the new release causing Twitter Pull to fail? Any advice?
Comment | File | Size | Author |
---|---|---|---|
#9 | 2562681-twitter-pull-incompatible-with-twitter-5.9_9.patch | 1.78 KB | kalabro |
Comments
Comment #2
glynster CreditAttribution: glynster commentedComment #3
stevensunsunsun CreditAttribution: stevensunsunsun commentedSame issue.
Twitter 5.9 caused Twitter Pull Authentication to fail.
Reverting to 5.8 fixed this.
Comment #4
kaosagnt CreditAttribution: kaosagnt commentedYep many APIs have changed. This is the one killing Twitter Pull.
--- a/cgi-bin/XXX_XXX/sites/all/modules/twitter/twitter.inc
+++ b/cgi-bin/XXX_XXX/sites/all/modules/twitter/twitter.inc
@@ -10,28 +10,47 @@
/**
* Connect to the Twitter API.
*
- * @param object $account
+ * @param object $twitter_account
* An authenticated twitter_account object to be used to authenticate against
* Twitter.
+ * @param bool $access_global
+ * Whether or not to load the global accounts too.
+ * @param bool $force
+ * Loads accounts regardless of other access limits. Should be used with care
+ * and only for limited scenarios that do would not pose a security risk.
+ *
* @return
- * a Twitter object ready to be used to query the Twitter API or FALSE.
+ * A Twitter object ready to be used to query the Twitter API or FALSE.
*/
-function twitter_connect($account = NULL) {
- if (!$account) {
- // Load the first authenticated account.
- $twitter_uid = db_query("SELECT twitter_uid
- FROM {twitter_account}
- WHERE oauth_token <> ''
- AND oauth_token_secret <> '' ")->fetchField();
- $account = twitter_account_load($twitter_uid);
- }
- if ($account) {
- $auth = $account->get_auth();
- if (isset($auth['oauth_token']) && isset($auth['oauth_token_secret'])) {
- return new Twitter(variable_get('twitter_consumer_key', ''), variable_get('twitter_consumer_secret', ''),
- $auth['oauth_token'], $auth['oauth_token_secret']);
+function twitter_connect($twitter_account = NULL, $access_global = FALSE, $force = FALSE) {
+ // If no account was specified, load the first authenticated account.
+ if (empty($twitter_account)) {
+ // Load all authenticated accounts, passing in the same access requirements.
+ $accounts = twitter_load_authenticated_accounts(NULL, $access_global, $force);
+
+ // If no accounts were found, there's a problem.
+ if (empty($accounts)) {
+ watchdog('twitter', 'There are no authenticated Twitter accounts to use for API connections.');
+ }
+
+ // Grab the first authenticated account.
+ else {
+ $twitter_account = reset($accounts);
}
}
+
+ if (!empty($twitter_account)) {
+ $auth = $twitter_account->get_auth();
+ if (isset($auth['oauth_token']) && isset($auth['oauth_token_secret'])) {
+ return new Twitter(
+ variable_get('twitter_consumer_key', ''),
+ variable_get('twitter_consumer_secret', ''),
+ $auth['oauth_token'],
+ $auth['oauth_token_secret']
+ );
+ }
+ }
+
return FALSE;
}
For now I've change my twitter pull twitter_pull.class.inc
- $twitter = twitter_connect();
+ $twitter = twitter_connect(NULL, TRUE);
and made the twitter account global. We only have one account pulling tweets and don't have any other twitter functionality enabled.
Comment #5
glynster CreditAttribution: glynster commentedI applied your small change and this did not work for me. I still receive the same 3 errors.
Comment #6
jesss CreditAttribution: jesss commented@kaosagnt's change in #4 worked for me. I'm also only using one account to pull tweets and no other Twitter functionality.
To clarify the steps:
1) Edit line 171 of twitter_pull.class.inc from:
to
2) Go to admin/config/services/twitter and check the "Global" option for the account that you want to pull.
Comment #7
glynster CreditAttribution: glynster commentedAwesome that worked a treat. I missed the global trick! Thank you so much for the help.
Comment #8
Beezer75 CreditAttribution: Beezer75 commentedI just ran into the same problem, #6 fixed it for me. Thank you all for posting this!
Comment #9
kalabroAttached patch fixes Twitter Pull for me. It will work for Twitter Key setting "@twitter_name" without Global option. For other cases (like "#drupal") you still need at least one global account.
Comment #10
martins.bertins CreditAttribution: martins.bertins at Wunder commented#9 patch worked for me. Thanks!
Comment #11
glynster CreditAttribution: glynster commented#9 patch also worked for me!! +1 to have this committed.
Comment #12
milodesc#9 seems to be working for me as well, and I'm using the 5.10 version of the twitter module.
Thanks for the patch.
Comment #13
kenorb CreditAttribution: kenorb commentedApplied patch, Twitter now works fine.
Comment #14
glynster CreditAttribution: glynster commentedRemoved.
Comment #15
achapThe patch in #9 works for me. +1 to have this committed.
Comment #16
jennypanighetti CreditAttribution: jennypanighetti commented+1 for committing please. Thanks!
Comment #17
agileadamPatch in #9 worked perfectly for me as well.
Comment #18
hey_germanoWorking for us, too. Thanks!
Comment #19
e.ryan.schmidt@gmail.com CreditAttribution: e.ryan.schmidt@gmail.com as a volunteer commentedI've been trying to figure this out for a few days -- #6 worked like a charm. Cheers!
Comment #20
dbazuin CreditAttribution: dbazuin at LimoenGroen commentedThe patch from comment #9 works for me.
looks like it is RTBC.
Comment #22
joachim CreditAttribution: joachim commented