Twitter API Issue


(Rob) #1

**Matrix Version: v5.4.3.1 **

Hi all,

I’m wracking my brain as to why the Oauth asset and the rest resource JS asset are throwing up the below error when I run the http test.

What’s even more frustrating is that the Oauth url to authenticate the Twitter account (page where you physically have to login/authinticate via twitter) works intermittently.

I’ve had it working and it will display the latest tweets but then after a certain amount of time it will just stop displaying anything.

I’ve got a feeling it’s to do with internal network Squiz is running on as i’m getting a “body” => "{“errors”:[{“code”:215,“message”:“Bad Authenticati…”

I could understand if it just didn’t work at all but seeing as it has worked and then stops is baffling!

Cheers,

Rob

"request" => array (
    "method" => "GET",
    "headers" => array (
        [Empty]
    ),
    "body" => "",
    "urls" => array (
        0 => "https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=devrwk&count=5" 
    ),
    "auth" => array (
        "type" => "OAuth" 
    ),
    "oauth_headers" => array (
        [Empty]
    ),
    "url" => "https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=devrwk&count=5" 
),
"responses" => array (
    0 => array (
        "body" => "{\"errors\":[{\"code\":215,\"message\":\"Bad Authenticati...",
        "headers" => array (
            "content-encoding" => "gzip",
            "content-length" => "87",
            "content-type" => "application/json; charset=utf-8",
            "date" => "Wed, 20 Mar 2019 16:14:37 GMT",
            "server" => "tsa_f",
            "set-cookie" => "guest_id=v1%3A155309847695805192; Max-Age=63072000; Expires=Fri, 19 Mar 2021 16:14:36 GMT; Path=/; Domain=.twitter.com",
            "strict-transport-security" => "max-age=631138519",
            "x-connection-hash" => "b46845f6e0a28f88715bea7f0610cbfb",
            "x-response-time" => "116",
            "Age" => "2",
            "Via" => "1.1 Clearswift SECURE Web Gateway" 
        ),
        "info" => array (
            "url" => "https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=devrwk&count=5",
            "content_type" => "application/json; charset=utf-8",
            "http_code" => 400,
            "header_size" => 679,
            "request_size" => 389,
            "filetime" => -1,
            "ssl_verify_result" => 0,
            "redirect_count" => 0,
            "total_time" => 0.195644,
            "namelookup_time" => 0.000981,
            "connect_time" => 0.008549,
            "pretransfer_time" => 0.03426,
            "size_upload" => 0,
            "size_download" => 87,
            "speed_download" => 444,
            "speed_upload" => 0,
            "download_content_length" => 87,
            "upload_content_length" => 0,
            "starttransfer_time" => 0.19547,
            "redirect_time" => 0,
            "redirect_url" => "",
            "primary_ip" => "10.201.64.153",
            "certinfo" => array (
                [Empty]
            ) 
        ),
        "source" => "remote",
        "expiry" => 0 
    ) 
),
"response" => array (
    "body" => "{\"errors\":[{\"code\":215,\"message\":\"Bad Authenticati...",
    "headers" => array (
        "content-encoding" => "gzip",
        "content-length" => "87",
        "content-type" => "application/json; charset=utf-8",
        "date" => "Wed, 20 Mar 2019 16:14:37 GMT",
        "server" => "tsa_f",
        "set-cookie" => "guest_id=v1%3A155309847695805192; Max-Age=63072000; Expires=Fri, 19 Mar 2021 16:14:36 GMT; Path=/; Domain=.twitter.com",
        "strict-transport-security" => "max-age=631138519",
        "x-connection-hash" => "b46845f6e0a28f88715bea7f0610cbfb",
        "x-response-time" => "116",
        "Age" => "2",
        "Via" => "1.1 Clearswift SECURE Web Gateway" 
    ),
    "info" => array (
        "url" => "https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=devrwk&count=5",
        "content_type" => "application/json; charset=utf-8",
        "http_code" => 400,
        "header_size" => 679,
        "request_size" => 389,
        "filetime" => -1,
        "ssl_verify_result" => 0,
        "redirect_count" => 0,
        "total_time" => 0.195644,
        "namelookup_time" => 0.000981,
        "connect_time" => 0.008549,
        "pretransfer_time" => 0.03426,
        "size_upload" => 0,
        "size_download" => 87,
        "speed_download" => 444,
        "speed_upload" => 0,
        "download_content_length" => 87,
        "upload_content_length" => 0,
        "starttransfer_time" => 0.19547,
        "redirect_time" => 0,
        "redirect_url" => "",
        "primary_ip" => "10.201.64.153",
        "certinfo" => array (
            [Empty]
        ) 
    ),
    "source" => "remote",
    "expiry" => 0 
)

(Tbaatar) #2

Hi Rob,

Not sure why it doesn’t work for you but I had the example Twitter implementation working for the past 2-3 years on variou Squiz build going back to even version 4.19.

Here is an example running on v5.5.1.5:
http://bornresponsive.com/_core/api/twitter/twitter-feed

Here is the steps I have taken to get it working:

  • Rest Resource oAuth Session has public permission and live
  • After authorization you will just get a blank white page (or depending on the design file set to this asset).
  • Go back to the details screen of the Rest Resource oAuth Session and check if it has the Access Token.
  • If yes, it means it has worked and therefore set the Store Access Token to Yes.
  • Now Create a Rest Resource JS asset and set the Auth type to oAuth and include the oAuth Session asset.
  • As for setting up the Twitter Feed, use the the following example provided by Squiz in the Rest JS body:
var statuses = eval('(' + _REST.response.body + ')');
print('<ul>');
for (i = 0; i < statuses.length; i++) {
    print("<li><strong>" + statuses[i].user.name + "</strong>");

    var text = statuses[i].text;

    // Replace t.co URLs with their full versions.
    var urls = statuses[i].entities.urls;
    for (var j = 0; j < urls.length; j++) {
        text = text.replace(urls[j].url, '<a href="' + urls[j].expanded_url + '">' + urls[j].url + '</a>');
    }

    // Replace hashtags with Twitter searches.
    var tags = statuses[i].entities.hashtags;
    for (var j = 0; j < tags.length; j++) {
        text = text.replace('#' + tags[j].text, '<a href="http://twitter.com/search/%23' + tags[j].text + '">#' + tags[j].text + '</a>');
    }

    // Replace user mentions with Twitter URL links.
    var users = statuses[i].entities.user_mentions;
    for (var j = 0; j < users.length; j++) {
        text = text.replace('@' + users[j].screen_name, '<a href="http://twitter.com/' + users[j].screen_name + '">@' + users[j].screen_name + '</a>');
    }

    print(" : " + text + "</li>");
}
print('</ul>');  

The only thing I can think of is that the stored token could have been lost? or some changes were made to the twitter oAuth parameters by someone?


(Rob) #3

Hi Tba!

Sorry for the delayed response - I logged off our network before you sent this! Wasn’t expecting such a fast response.

I hadn’t though to check that the Oauth asset was public - our public access user permission profile is currently set to ‘under construction’ so I wonder if that’s causing any issues.

Will try your instructions and see how I get on. I’m also going to run the same setup on the VM that’s on my Mac and is outside of our network to see if that works too.

Thanks again for the help,

Rob


(Rob) #4

I’ve raised an issue with our root user as i’ve set it up again but it’s just not storing the Access Tokens.

I get as far as the attached then when I go back into the matrix to view the stored tokens nothing has changed…

I’m guessing I cant actually test this via the VM as it doesn’t have a live route out to twitter?


(Rob) #6

Looks like it’s a network thing where our ClearSwift software prevents authentication from outside the network. I get similar issues when trying to use the Repo asset to connect to github. Makes developing incredibly frustrating and slow with so many restrictions!


(Tbaatar) #7

Can you setup the auth outside the network? Once this is authenticated do you experience any problems?


(LunaticEssence) #8

I hope that since the original thread, you’ve made progress in resolving your API issues. If you have any more questions or updates to share, please feel free to do so.


(Termanyw) #9

I can understand your frustration with the intermittent Twitter API issues you’ve been facing, even though the thread is from four years ago. Technical challenges, especially when they appear intermittently, can be quite puzzling.
It’s worth exploring various factors that could contribute to these problems, such as changes in Twitter’s API or network configurations. Sometimes, it’s challenging to pinpoint the exact cause of such issues.
If you’re still working on Twitter integration and require a more stable presence on the platform, you can try to Buy Old Twitter Accounts. These accounts can provide a consistent base for your API integration efforts and potentially help in avoiding some of the intermittent issues you’ve encountered.