Closed biplovkc closed 7 years ago
@cybercop I'll look into that ;)
What version of Skybrud.Social are you using?
0.9.6
@cybercop I haven't been able to reproduce the issue in my end.
Are you sure that neither ClientId
, ClientSecret
or RedirectUri
are empty or null when calling GetAccessTokenFromAuthCode
? If at least one of them is missing, then I'm able to reproduce the same exception.
nope they are not null
The Instagram API is most likely responding with an error, which isn't handled properly in my code. So in your OAuth method, could you try replacing the existing with the following code:
// Initialize collection with POST data
NameValueCollection parameters = new NameValueCollection {
{"client_id", client.ClientId},
{"client_secret", client.ClientSecret},
{"grant_type", "authorization_code"},
{"redirect_uri", client.RedirectUri},
{"code", code }
};
// Make the call to the API
string body = SocialUtils.DoHttpPostRequestAndGetBodyAsString("https://api.instagram.com/oauth/access_token", null, parameters);
and then post the contents of body
? The API should respond with a JSON body - even for error responses.
Alternatively, you could try installing Skybrud.Social.Instagram
(the package in this repository, actually) instead. Right now you have Skybrud.Social
, which is currently the stable version, and which has support for a number of services (including Instagram) by default.
Skybrud.Social
will soon be replaced by individual packages instead, where Skybrud.Social.Instagram
(still beta'ish at the moment) will be the package for Instagram. Skybrud.Social.Instagram
already has better error checking than Skybrud.Social
;)
I installed Skybrud.Social.Instagram as you said. But the error now says invalid client secret. Which clearly is not
I also reset my secret and tried the new secret key but still same error.
If my client secret was wrong would I still get code for access token?
In the screenshot above, doesn't your client secret have a space at the end?
Ah sorry for the stupidity. it works now thank you! Is there any documentation regarding, how to get some pictures by username? (lets say 20 images)
No worries ;)
Regarding looking up pictures by a given username: you can't. But you can do a search first for the username first to find the ID of the user, and then request images for that user ID.
here's some documentation:
This is what I am doing right now
``
I get error in line InstagramAccessTokenResponse response = client.GetAccessTokenFromAuthCode(code);
An exception of type 'System.NullReferenceException' occurred in Skybrud.Social.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
I am getting the code values but the access token doesn't work after getting the code