2

Is there a way of detecting a pinned tweet using the array returned from the twitter api? I have print_r the array returned and nothing indicates a tweet is pinned or not.

The method I currently use is

$statuses = $connection->get("statuses/home_timeline", array("count" => 25, "exclude_replies" => true));

The documentation does not mention pinned tweets https://twitteroauth.com/

5

The user profile shows pinned tweets

https://api.twitter.com/1.1/users/show.json?id=2705321

"has_extended_profile": true,
"default_profile": false,
"default_profile_image": false,
"pinned_tweet_ids": [
  451484520316153860
],
"has_custom_timelines": false,
0

There's no way to get it through the API, but it's fairly easy to scrape the data from the website*. The HTML has lots of useful semantic attributes which you can use.

Here's the HTML representation of my pinned Tweet.

<div 
    class="tweet original-tweet js-original-tweet js-stream-tweet js-actionable-tweet js-profile-popup-actionable cards-forward
    user-pinned" 
    data-tweet-id="554772317738659840"
    data-disclosure-type=""
    data-item-id="554772317738659840"
    data-permalink-path="/edent/status/554772317738659840"
    data-screen-name="edent"
    data-name="Terence Eden" 
    data-user-id="14054507"
    ...

Look for the <div> with the class user-pinned - then get the attribute data-tweet-id. That will be the status ID which has been pinned.

*Check the T&Cs first!

-1

No, there's currently no way to either detect or set a pinned Tweet using the public Twitter APIs.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.