3

I'm using InstaSharp to get all medias from my account. This code works without any error:

 var user = new InstaSharp.Endpoints.Media.Authenticated(config, authInfo);
 var media = user.Popular();

Now if I do the same with Users:

var user = new InstaSharp.Endpoints.Users.Authenticated(config, authInfo);
var feed = user.Feed("self");

This returns:

OAuthParameterException: The access_token provided is invalid.

Why the same access token works in one place but doesn't work in another?


Note: I'm passing all scopes (basic, comments, likes, relationships) while getting the access token.I have also tried with default (basic) and it didn't work either.

Note2: Since I'm trying this in a ConsoleApplication, the way I'm getting the access token is, generate the link, copy/paste to the browser, confirm the authorization and get it from url. I'm not sure it makes any difference but it's worth noting...

JP Hellemons
  • 5,977
  • 11
  • 63
  • 128
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • The Instagram API wants the request as: https://api.instagram.com/v1/users/self/... Your API adds 'self' for you `var request = Request("self/feed")`; (line 87 `Endpoints.Users`). The params passed (`Feed(string maxId, string minId, int? count)`) are apparently the min and max feed ids to get. No idea why you dont get an error passing only 1 string param (unless I have dug into the wrong thing or you are using an old version?). The code on GitHub matches the docs including the Min Max ID portion. – Ňɏssa Pøngjǣrdenlarp Dec 22 '14 at 22:59

1 Answers1

2

I figure out the problem. It seems that the generated link was requesting code, not access_token.So that's why it was invalid.

And I realized that I was using older version of InstaSharp even though I downloaded it from it's website. First, I installed the latest version via NuGet. Then, I get the access token and the media like this:

var config = new InstagramConfig(clientId, clientSecret);
var AuthLink = OAuth.AuthLink(config.OAuthUri + "/authorize", 
                              config.ClientId, 
                              config.RedirectUri,
                              scopes, 
                              OAuth.ResponseType.Code);

var authInfo = new OAuth(config);

// get the code from the link then pass it to RequestToken
var response = await authInfo.RequestToken(code);
var user = new Users(config, response);
var media = await user.RecentSelf(count: 30);

And all worked very well.

Selman Genç
  • 100,147
  • 13
  • 119
  • 184