skip to Main Content

I want to get a Tweets list using GET statuses/home_timeline. My Resource URL without any additional parameters. When I send a request, I get the error Forbidden. A part of of code below

  public async Task<BindableCollection<Tweet>> Execute()
    {
        string uri = "https://api.twitter.com/1.1/statuses/home_timeline.json";

        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Add("Host", "api.twitter.com");
        client.DefaultRequestHeaders.Add("Authorization", info.TokenType + ' ' + info.AccessToken);

        HttpResponseMessage responce = new HttpResponseMessage();

        while (true)
        {
            try
            {
                responce = await client.GetAsync(uri);
                break;
            }
            catch { Debug.WriteLine("ERROR!"); }
        }

info.TokenType and info.AccessToken contain “bearer” and my access token
in accordance.
Appropriate photo

When I sent the request (GET statuses / USER_timeline) with this parameters (TokenType and AccessToken)I got the correct answer.

Any ideas on this?

3

Answers


  1. HOME_timeline requires user authentication as opposed to application authentication, which can be used with User_timeline. Are you authenticated using application credentials perchance?

    From the docs:

    “With Application-only authentication you don’t have the context of an authenticated user and this means that any request to API for endpoints that require user context, such as posting tweets, will not work. However, the set of endpoints that will still be available can have a higher rate limit.”

    Login or Signup to reply.
  2. As Ian Nelson said you need an authorization to access to your timeline. But you can use LinqToTwitter for getting a list of tweets.

     var tweets = from tweet in twitterContext.Status
                    where tweet.Type == StatusType.User
                          && tweet.ScreenName == "Goofy"
                    select tweet;
    
    Login or Signup to reply.
  3. you need to differentiate HomeTimeline and UserTimeline.

    • HomeTimeline is the timeline of the currently authenticated user, so you must have a user specific authentication.
    • UserTimeline is the public timeline of a specific user, you can use Application-Only authentication.

    Tweetinvi gives a very straight access to both of these :

    var tweets = Timeline.GetHomeTimeline();
    // OR
    var tweets = Timeline.GetUserTimeline(<user_identifier>);
    

    Timeline documentation

    For authentication you will also need 1 line:

    // User authentication
    Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
    // Application-Only authentication
    Auth.SetApplicationOnlyCredentials("CONSUMER_KEY", "CONSUMER_SECRET", true);
    

    Authentication documentation

    Let me know if this is of any help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search