explorer api gives diffrent result sets with same permission access token - facebook-graph-api

I have a web page calling me/feed.
The result set I got is different from using api explorer.
I debugged both access_tokens, they have same access rights.
However, if I used access token created by explorer in my web page(hard code), then I got the same result as api explorer.
below are screenshot for those two access_tokens, could not see any difference apart from application id
explorer token screen shot
My own app token screen shot
Any ideas please?
Belows are code about I obtains my own token
FB.init({
appId: '138930956203643',
channelUrl: '//www.lbm.co.uk/channel.htm',
cookie: true,
status: true,
xfbml: true,
oauth: true
});
FB.login(function (response) {
if (response.authResponse) {
// alert('Authorization result: ' + response.status);
access_token = response.authResponse.accessToken;
uid = response.authResponse.userID;
$("#loginbutton").hide();
$("#logoutbutton").show();
getUserInfo(); // Get User Information.
getLikes();
} else {
alert('Authorization result: ' + response.status);
}
}, { scope: 'user_likes, email, user_friends,read_stream, export_stream' });
Then I call get feed
$.get('https://graph.facebook.com/' + uid + '/feed?
method=GET&format=json&suppress_http_code=1&access_token='+ access_token, getFeedNext,
"json");
Note, for same code, if I replace access_token with the one from explorer, it returns same result

Related

Ionic facebook login for native

I have implemented the facebook login for my ionic application, which works perfectly when run on web. When i build the application, create an apk of the same, and try to run on my mobile device, nothing happens.
The login is:
openFB.login(
function (response) {
if (response.status === 'connected') {
console.log('Facebook login succeeded, got access token: ', response);
openFB.api({
path: '/me',
success: function (data) {
console.log("My Data", data);
userData.name = data.name;
userData.picture = 'http://graph.facebook.com/' + data.id + '/picture?type=small';
localStorageService.set('user', userData);
$timeout(function() {
$state.go('app.home');
}, 0);
},
error: function(error) {
console.log("Error here:", error);
}
});
} else {
console.log('Facebook login failed: ' + response);
}
}, { scope: 'email, public_profile' });
Have used openFB for the login. After clicking, following popup comes up.
After clicking the okay, nothing gets logged. No console message.
Can some one help me for finding out this issue, where i am not able to do the facebook login, when run on actual device.
You need to whitelist the redirect url. You can set it in
Products > Facebook Login > Settings > Client OAuth Settings
Take a look into this question.
please set redirect URI in
Products > Facebook Login > Settings > Client OAuth Settings
http://localhost/callback
please follow the below procedure to register your app in facebook developer site
https://ccoenraets.github.io/ionic-tutorial/ionic-facebook-integration.html
and use the below code to complete the procedure of facebook login
$cordovaOauth.facebook("appId", ["email", "public_profile"]).then(function(result) {
//alert(JSON.stringify(result));
//$localStorage.accessToken = result.access_token;
$http.get("https://graph.facebook.com/v2.2/me", {
params: {
access_token: result.access_token,
fields: "id,name,gender,location,email,picture,relationship_status",
format: "json"
}
}).then(function(result) {
// alert(JSON.stringify(result));
$scope.loginflowusingsociallogin(result.data.email);
}, function(error) {
alert("There was a problem getting your profile. Check the logs for details.");
alert(JSON.stringify(error));
});
});
i used Oauth 2.0 authentication for ionic.
I used this code and worked fine for me

How do I get the "address consent token" after Amazon login?

I am using the OffAmazonPayments JS library to allow users to log into their Amazon account, access their address book, and eventually to pay with their Amazon account. The AddressBook widget will let me retrieve general address info, but without the address consent token, I cannot get the street address.
http://docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetOrderReferenceDetails.html
This link indicates that I can retrieve the address consent token from the Button object after authentication, but it's not clear how that works; in the definition of the sign-in Button, there's an "onSignIn" callback which receives an orderReference object, but that object doesn't seem to contain any such token.
Please see the Amazon Payments documentation..specifically this page: https://payments.amazon.com/documentation/lpwa/201953150
As you can see in the following code snippet (taken from said page) you can retrieve the token from the "amazon.Login.authorize(...)" function.
Note: You first must include in the "scope" parameter "payments:shipping_address" as one of your scopes in order to get the "address consent token". Below I'm including other scopes so you can see how to list more than one.
The CAPS words/parameters would be replaced by your own desired parameters.
<script type="text/javascript">
var authRequest;
var addressConsentToken;
OffAmazonPayments.Button("AmazonPayButton", "YOUR_SELLER_ID", {
type: "ENTER_TYPE_PARAMETER",
color: "ENTER_COLOR_PARAMETER",
size: "ENTER_SIZE_PARAMETER",
language: "ENTER_LANGUAGE_PARAMETER",
authorization: function() {
loginOptions = {scope: "profile payments:widget payments:shipping_address",
popup: "ENTER_POPUP_PARAMETER"};
authRequest = amazon.Login.authorize (loginOptions,
function(response) {
addressConsentToken = response.access_token;
});
},
onSignIn: function (orderReference) {
var referenceId = orderReference.getAmazonOrderReferenceId();
if (!referenceId) {
errorHandler(new Error('referenceId missing'));
} else {
window.location = "YOUR_REDIRECT_URL" + '?referenceId=' +
orderReference.getAmazonOrderReferenceId() +
"&access_token=" + addressConsentToken;
}
},
onError:errorHandler || function(error) {
// your error handling code
}
});
</script>

Facebook Javascript SDK extend access token get "Invalid OAuth access token" - 190 - "OAuthException"

I try to use javacript SDK to get access token and then extend that access token for 60 day. I got reponse error like this from response: Object { message="Invalid OAuth access token.", type="OAuthException", code=190}
My expectation:
Get new access token with 60 days expire
Console to screen.
My Code:
window.onload = function() {
var isLogin = true;
FB.init({appId:422642254433770, cookie:true, status:true, xfbml:true });
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and connected to your
// app, and response.authResponse supplies
// the user’s ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
var accessTokenOld = response.authResponse.accessToken;
//Extend access token
var OauthParams = {};
OauthParams['client_id'] = '//REMOVED APP ID';
OauthParams['client_secret'] = '//REMOVED APP SECRET';
OauthParams['grant_type'] = 'fb_exchange_token';
OauthParams['fb_exchange_token'] = 'accessToken';
OauthParams['response_type'] = 'token';
console.log("Old accessToken => " + accessToken);
FB.api('/oauth/access_token', 'post', OauthParams, function(response) {
console.log(response);
if (!response || response.error) {
console.log(response.accesstoken);
} else {
console.log("Lay new access token bi loi " + response.error.message);
}
});
}
});
};
I try to search every where for this trouble 3 days without any clue. I there any one have experience? please help.
Many thanks
Doing this in a client is a bad idea because of the requirement to include the app secret in the actual client, which is very dangerous. It's best to call a endpoint on your server that handles this separately so that app secret stays in your controlled environment.
If in Advanced Settings of your FB App you have 'Remove offline_access permission' enabled, all your access tokens will be 60 days by default.
We ran into this same issue recently and this fixed the problem.
Hope this helps!
I found a simple solution to get extended access token using Jquery valide upto 2 months
Variables to pass to the URL:
var accessToken = 'CURRENT_ACCESS_TOKEN';
var appid = 'APPID';
var appsecret = 'APPSECRET';
Your URL should point to
var exchangeUrl = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&fb_exchange_token="+accessToken+"&client_id="+appid+"&client_secret="+appsecret;
Make an Ajax request as
$.ajax({
type: "GET",
url: exchangeUrl,
success: function(data)
{
extended = data.split('=');
extendedAT = extended['1'].replace('&expires','');
alert(extendedAT);
}
});

Update / Delete a tab from a facebook page using the Graph API returns "(#210) Subject must be a page."

I am trying to delete an application tab from a facebook page.
According to the documentation, I should issue a DELETE request to "https://graph.facebook.com/PAGE_ID/tabs/TAB_ID" with a PAGE access token, but when I do so I get the error "(#210) Subject must be a page."
The same happens when trying to update a tab.
I have requested the user for "manage_pages" permission and I have the correct access_token (Adding a tab works perfectly).
the exact request is: https://graph.facebook.com/212757048770606/tabs/app_289329597785433 (with an access token)
Does anyone know what am I doing wrong?? or is there an open bug report?
Thanks alot
I don't have a solution for you, but I do know that I had some problems with removing a tab that boiled down to the fact that the tab's ID (returned from a call to get /PAGE_ID/tabs) already includes the page ID and "tabs" path.
Initially I was building my URL by taking the tab ID and sticking it on the end of /PAGE_ID/tabs/, but that didn't work because the URL ended up being something like /12345/tabs/12345/tabs/app_4567. Once I realized that the tab ID was sort of "compound" already, I got the Remove to work.
Add the page access token to the call of Facebook API
var PageAccessToken = 123456789123456789123456789123456789;
FB.api(
"/{page_id}/tabs",
"POST",
{
"object": {
"app_id": "{page_id}"
}
},{
"access_token": PageAccessToken
},
function (response) {
if (response && !response.error) {
console.log(response);
} else {
console.log(response.error);
}
}
);
function DeleteTabPage(){
var pid = page_id;
var at = access_tocken;
debugger;
FB.api(pid + '/tabs/app_{your app id}', 'DELETE', { app_id: your app id, access_token: at }, function (response) {
debugger;
if (!response || response.error) {
debugger;`enter code here`
alert('Facebook add app error ' + response.error);
} else {
console.log(response);
debugger;
// alert('App has been added');
}
}); /* end of page/tabs*/
}

pages.isFan returns incorrect signature

I am working on a Facebook canvas iFrame application, and I`m going insane.
I am trying to check if a user is a fan of the page where the app is located, so that I can allow or disallow voting.
I use the following code:
function CheckFan() {
FB.init({
appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.api({ method: 'pages.isFan', page_id: '145116742177104' }
, function(resp) {
if (resp) { $('#main_frame').show(); $('#non_fan').hide(); }
else { $('#main_frame').hide(); $('#non_fan').show(); }
});
}
This JS SDK is driving me up the wall, while calling the documentation "incomplete" is an insult to incompleteness.
Any input will be appriciated.
Thank you!
-Elad
This has been deprecated by Facebook.
A new Graph API alternative will hopfuly be available by the time we need to deploy the app.
For now I use FQL:
FB.api({ method: 'fql.query', query: 'SELECT uid FROM page_fan WHERE uid= ' + user_id + ' AND page_id=145116742177104' },
function(result) {
if (result.length)
{ $('.main_frame').show(); $('#non_fan').hide(); } else { $('.main_frame').hide(); $('#non_fan').show(); }
});