"(# 100) You must provide an application access token or user access token who owns or is the developer of the application" (see Description)? - facebook

I make a request to find out the data about my user access token:
fetch("https://graph.facebook.com/v8.0/debug_token?input_token=" + access_token).then(function (response) {
response.text().then(function (textII) {
alert(textII);
});
});
In this case, I take the accessToken value from auth Response after authorization to the application and Facebook:
{
status: 'connected',
authResponse: {
accessToken: '{access-token}',
expiresIn:'{unix-timestamp}',
reauthorize_required_in:'{seconds-until-token-expires}',
signedRequest:'{signed-parameter}',
userID:'{user-id}'
}
}
But I get an error:
{
"error": {
"message": "(#100) You must provide an app access token or a user access token that is an owner or developer of the app",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AtpM_XaTOgH7YH-OXHdQCXj"
}
}
The value of my variable access_token is not null (I checked), while this is sort of a user access token (the keyword "sort of"). So what's wrong? Explain, please. If you need information about what I need it for, then I need it for this request:
for (var iio = 0; iio < posts_ids.length; iio++) {
fetch("https://graph.instagram.com/" + posts_ids[iio] + "?fields=id,media_type,media_url,owner,timestamp&access_token=" + access_token).then(function (response) {
response.text().then(function (textII) {
alert(textII);
});
});
}
Which throws an error:
{
"error": {
"message": "Invalid OAuth access token.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "AD7BAPqUGdQGC6dyV9K_FFr"
}
}
At the same time, in my previous requests, just starting with "https://graph.facebook.com/", and not "https://graph.instagram.com/", everything worked with the accessToken that I received after registration.
Help me please. I'm new to the Instagram API, so I can be pretty dumb.

Please turn off the setting(Setting -> Advanced -> Application authentication), it works!

#Denis Bredun , you would have to pass access_token field also as the URL param, so just update the url to -
https://graph.facebook.com/v8.0/debug_token?input_token=<access_token>&access_token=<access_token>

Try resetting your app secret. I was getting the same problem, and this fixed it.

I solved the error by changing the app secret to the correct one.
Make sure you are using the proper app secret.

For me, using the debug_token api requires the "page token" and the "app token" and then you call the api in the format :
https://graph.facebook.com/v<version>/debug_token?input_token=<page_token>&access_token=<app_token>
As per the facebook doc To get the app_token, you need the app id and app secret. And then you call https://graph.facebook.com/oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=client_credentials
To get the page_token, this is done by first getting the user_token, then you convert the user_token into a long lived user token, and then you get the page token calling the api "/<page_id>?fields=access_token".
Note that you will need the proper permissions on the user_token to do that, like "pages_read_engagement" otherwize you will get an error from the api trying to get the page token.

Related

Share an image to Faceboook

I need to share an image to facebook. For this I am trying the API call suggested here
FB.login(function(response) {
if (response.authResponse) {
FB.api(
"/{page-id}/photos",
"POST",
{
"url": "https:\/\/www.facebook.com\/images\/fb_icon_325x325.png",
"published": "false"
},
function (response) {
if (response && !response.error) {
console.log(JSON.stringify(response))
/* handle the result */
}
else
{
console.log("ERROR: " + JSON.stringify(response))
}
}
);
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
But I am getting an error (#803) Some of the aliases you requested do not exist: {page-id}
Is page-id the same as the userID returned in the authResponse? Because I also tried hardcoding that id, but I got a deprecated API message.
I need to allow the user to share the photo directly to his feed.
Thanks
Page ID and User ID are not the same. You get a User ID after authorization, you get a Page ID by using the /me/accounts endpoint with a User Token. You can also get Page Tokens with /me/accounts?fields=access_token. You need to use a Page Token with the publish_pages and manage_pages permissions to create posts or photos on a Page you manage.
As WizKid commented, you can also just use /me/photos to upload photos. Just use a Page Token.
More information: https://developers.facebook.com/docs/facebook-login/access-tokens/

Spotify FB Login with preview api

Anyone knows how the facebook login works with the new preview spotify apps api?
I tried something like this...
require(['$api/facebook'], function(facebook) {
facebook.session.showConnectui();
}
but nothing got me to the result I got with the old api. I also tried to use plain FB js sdk, but the problem is it needs some "url" to allow connections...wich I can't really give out of the spotify app?
Any ideas?
The auth module was not present at first, but now it is part of the Spotify Apps API. You can read more about it on its documentation page. It looks like this:
require(['$api/auth#Auth'], function(Auth) {
var appId = '<your_app_id>',
permissions = ['user_about_me'];
var auth = new Auth();
auth.authenticateWithFacebook(appId, permissions)
.done(function(params) {
if (params.accessToken) {
console.log('Your access token: ' + params.accessToken);
} else {
console.log('No access token returned');
}
}).fail(function(req, error) {
console.error('The Auth request failed with error: ' + error);
});
}
});
In addition, there is a working example in the Tutorial App on GitHub.

get facebook access token is invalid

i can get access token from this link with some click :)
http://developers.facebook.com/tools/explorer
i retrived access token is long and it work for
graph.facebook.com/me/permissions?access_token
and other graph api
but when i get access token with this URL it is very short and not work
https://graph.facebook.com/oauth/access_tokenclient_id=MYID&redirect_uri=http%3A%2F%2Fbenbiddington.wordpress.com&client_secret=MYSECID&grant_type=client_credentials&scope=read_stream,manage_friendlists,read_mailbox,read_page_mailboxes
it dont work and return
{ "error": {
"type": "QueryParseException",
"message": "An active access token must be used to query information about the current user." } }
but is some case it work
This is a VB.NET example - but I use this get get an access token for a user all the time, and have never received the response you are showing - so maybe this will help?
Public Class FacebookAuthorization
Private Shared Property BaseURL As String = "https://graph.facebook.com/oauth/authorize"
Public Shared Function GetAuthUrl(ByVal appID As String, ByVal redirectUrl As String, ByVal permissions As String) As String
Return String.Format("{0}?client_id={1}&redirect_uri={2}&type=user_agent&scope={3}", BaseURL, appID, redirectUrl, permissions)
End Function
End Class
EDIT:
The access_token you get back from this request can be used like so:
https://graph.facebook.com/me/feed?access_token=XXXXXX - get's you their wall/timeline
https://graph.facebook.com/me/home?access_token=XXXXXX - get's you their news feed

facebook Access Token 400 bad request

I am using following code to retrieve facebook accessToken
string url = "https://graph.facebook.com/oauth/access_token?" +
"client_id={0}" +
"&redirect_uri={1}" +
"&client_secret={2}" +
"&code={3}";
url = string.Format(url, clientId, redirectUri.EncodeUrl(), clientSecret, code);
//Create a webrequest to perform the request against the Uri
WebRequest request = WebRequest.Create(url);
try
{
//read out the response as a utf-8 encoding and parse out the access_token
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
//string urlRedirects = response.ResponseUri.ToString();
Encoding encode = Encoding.GetEncoding("utf-8");
if (stream != null)
{
StreamReader streamReader = new StreamReader(stream, encode);
string accessToken = streamReader.ReadToEnd().Replace("access_token=", "");
streamReader.Close();
response.Close();
return accessToken;
}
}
}
}
catch
{
return null;
}
however I am constantly receiving this ambiguous error message
{
"error": {
"message": "Error validating verification code.",
"type": "OAuthException",
"code": 100
}
}
I checked the code 100 "Invalid parameter" doesn't means much to me at all.
anyone have had similar problem?
Check you are adding correct code in the url
For example
http://www.xyz.com/?code=AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20#_=_
Code must be
code = AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20
code should not include following in the end
#_=_
If above did not solve the problem
2. redirect_uri must end with /
redirect_uri=http://www.xyz.com/
The following gives some times above mentioned error
redirect_uri=http://www.xyz.com
3. A lso make sure
App on Facebook and Website with Facebook Login are set with same addresss
e.g http://www.xyz.com/
You need to send the user to the Facebook Login page to get a valid code. The code should then be used to get the access_token for the user.
Follow the Authentication Guide.
I also got error message 400, when my app id and secret were wrong (i had messed up develop and production id-s and secrets).
Fixing them (watch also out for the correct host) fixed this problem for me.

Could I Extend Facebook Access_Token Expiration Time without Single Sign-On?

I am a newbie on integrating facebook to iphone.
Now I encounter a problem when removing offline_access. Who can give me a hand? please
I use following code to get facebook authorization.
[facebook dialog:#"oauth" andParams:params andDelegate:self];
While when I extend access token with following code:
[facebook extendAccessTokenIfNeeded];
I encounter error: error_msg=The access token was not obtained using single sign-on, error_code=10
If I use following code to get authorization, I can extend access token.
[facebook authorize:permissions];
But I don't want my app directe to safari and then redirect to my app to get authorization
I see in Removal of offline_access permission, it says
Scenario 4: Client-side OAuth and Extending Access_Token Expiration Time through New Endpoint
Could I use it?
If yes, how to use it?
If no, is there any other method to extend access token? (without redirecting to safari)
{request_args=(
{
key = method;
value = "auth.extendSSOAccessToken";
},
{
key = sdk;
value = ios;
},
{
key = "sdk_version";
value = 2;
},
{
key = "access_token";
value = AAAAAK9pJJuEBAJ5VBsWIMjfdv6s9q6bXjO4AdO3diZA6s9ABEqS1VHNG1N5ynbvxyXVrFxTZAQ4RS8vww5hFPgb86TamBD0yjqPN75xopr8ACwqu8X;
},
{
key = format;
value = json;
}
), error_msg=The access token was not obtained using single sign-on, error_code=10}