i have:
user facebook data (
https://graph.facebook.com/btaylor )
facebook application data (
https://graph.facebook.com/2439131959
)
Is somehow possible to get if user is application administrator in facebook with this in my hands?
To get this kind of information you can use FQL:
protected function authorizeByFb(){
$result = $this->fb->api(array(
'method' => 'fql.query',
'query' => "SELECT developer_id FROM developer WHERE application_id='{$appId}' AND developer_id='{$fbUserId}'",
));
if(count($result)==1){
return true;
}
return false;
}
if your developed application is checking the role of the logged in facebook user or simply your application wants to recognize it's owner or admin,
then
http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts should have that application id listed
api call:
FB.api('/me/accounts', 'get', {"access_token":access_token}, function(response){
//loop through response to check any application id matches current application id
});
response sample:
{
"name": "app_name",
"access_token": "current_token_here",
"category": "Application",
"id": "your_owned_app_id"
},
{
"name": "app_name1",
"access_token": "current_token_here",
"category": "Application",
"id": "your_owned_app1_id"
},
I just got this to work using the Facebook JS API:
FB.api({ method: 'pages.isAdmin', page_id : fbAppId }, function(response){
if(response){
alert('the user is an admin');
}else{
alert('the user is not an admin')
}
});
It's using the FB.api method to access the old REST API. This assumes that you've already called FB.init, so make sure that this comes after your init code.
Cheers,
Jeremy
You can get the signed_request and then check if page_admin = 1
<?php
$signed_request = $facebook->getSignedRequest();
$page_admin = $signed_request["page"]["admin"];
if ( $page_admin == 1 ){
echo 'Welcome Admin!';
}
?>
I tried to attempted javascript form above and found this method to work as an alternative now that the old restful api is depreciated.
function checkAdmin(fbUID, fbAppID){
FB.api({
method: 'fql.query',
query: 'SELECT role FROM app_role WHERE developer_id ='+fbUID+' AND application_id = '+fbAppID
},
function(response) {
if(response.length){
alert('User is an Admin');
}
else{
alert('User is not an Admin')
}
});
}
Related
I am using an old SDK connection that works fine
<script src="http://connect.facebook.net/fr_FR/all.js"></script>
<fb:login-button show-faces="false" scope="email,user_birthday,user_location" size="medium">Facebook
</fb:login-button>
FB.api('/me?',
{ fields: 'name, email, gender,first_name,last_name,birthday,location' },
function(response) {
console.log(response);
});
that works fine.
When I try to add fields such as: user_location, user_birthday
response gives: error
Please see
https://developers.facebook.com/docs/graph-api/reference/user#Reading
for an overview which fields are available with the User object. The fields you're apparantly interested in are location and birthday.
FB.api('/me',
{ fields: 'name, email,gender,first_name,last_name,location,birthday' },
function(response) {
console.log(response);
}
);
I have been trying to create groups on facebook using Facebook Graph api. After referring this site http://developers.facebook.com/docs/concepts/app-game-groups/#impl where they have mentioned on how to create groups, i have written following code. But it is not working.can u plz help me on how to create groups on facebook
code:-
Ext.Ajax.request ({
url : 'https://graph.facebook.com/342283535872845/groups/description?access_token=342283535872845|9Adi1Gb9qf2UpcZHu_NywK5bBxI',
dataType: 'json',
timeout: 60000,
type:'POST',
success: this.Success,
failure: this.Failure,
scope: this
});
},
Response :-
{
"data": [
]
}
The response should have group id but instead i am getting null data.
Please help me with this on how to create groups?
You need to be the admin of the application and you must have the app access token.
Here is the sample code
$app_token = $app_id."|".$app_secret ; This is how you can gain the app access token
$response = $facebook->api(
"/APPID/groups", "POST",array (
'access_token' => $app_token,'name' => 'TEST NAME',
)
);
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*/
}
i have a question.... i am actually developing a facebook application with FB javascript SDK. In my application I need email permission for further processing. i am using
FB.Connect.showPermissionDialog("email");
but some how the dialog doesn't appears... here is my code
<script>
appid = '*************';
name = 'Palmchip Test App';
href = 'https://apps.facebook.com/*********/';
FB.init({
appId:appid, cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if (response.session) {
alert("You are logged in...");
FB.Connect.showPermissionDialog("email", function(perms) {
if (!perms) {
alert("no access");
} else {
alert("accessed...");
}
});
}
else {
top.location.href='https://graph.facebook.com/oauth/authorize?client_id='+appid+'&redirect_uri='+href+'&display=page';
}
});
</script>
the alert which says you are logged in... works fine but then nothing happens .....
You need to upgrade to OAuth 2.0 ouath: true
You should use the new OAuth Dialog
You should be aware when upgrading that FB.getLoginStatus() will return different objects: response.authResponse
Try this code block
FB.init({appId: <?= APP_ID ?>, status: true, cookie: true, xfbml: true, oauth:true});
function getin(){
FB.login(function(response) {
if (response.authResponse) {
var regurl = "/login";
location.href=regurl;
} else {
var regurl = "/logout";
window.location.href=regurl;
}
}, {scope:'email'});
}
So when you call the getin() function , if the current user already gave you the email address it'll do nothing for him just will redirect him to /login url , but if the user is a new user then he/she will see a pop-up box asking for the email address once he/she allows that you can pull the email address using graph or fql. BTW response inside FB.login has the user id , access_toke and some more useful data so save that for further use.
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(); }
});