Administrate facebook application via graph api - facebook

I was wondering if it is possible to change your site url or canvas url using the graph api. I have admin rights to my application and I can change it via the gui but I would prefer to be changing it via a curl.
Thanks

Here is example:
$properties = array(
"callback_url" => '',
"installable" => 1,
"profile_tab_url" => "",
"tab_default_name" => "",
'tos_url' => '',
'privacy_url' => ''
);
$facebook = new Facebook(array('appId'=>'YOUR_APP_ID','secret' = > '..', ...));
$facebook->api(array(
'method'=>'admin_setAppProperties',
'properties'=>json_encode($properties))
);
Here is a list of the properties you can set: http://developers.facebook.com/docs/appproperties/
There is also admin.getAppProperties more info you can find here: http://developers.facebook.com/docs/reference/rest/admin.getAppProperties/
Using Facebook SDK

You need to use the old REST method admin.SetAppProperties
https://developers.facebook.com/docs/reference/rest/admin.setAppProperties/
At the moment FB has not yet moved that method yet to the OpenGraph but you can still call REST methods via the Graph API (As shown in the console in the page above).
Even then you cannot change the secure_canvas and secure_tab url setting. FB is apparently working on make those settings as part of the API as far as I heard.

You can now change app properties via Graph API. You can make POST request, using the application id in the path, and use the app access token as the access token, and pass in key/value pairs as POST variables for properties you'd like to modify.
https://developers.facebook.com/docs/reference/api/application/ has a list of the application properties that you can modify with the Graph API.

Related

Facebook Graph API - Access token for page likes, name and url

I'm trying to update some old PHP code which is supposed to get the name, likes and a link to the given Facebook page. This is the current old code:
$fbsite1 = json_decode(file_get_contents('http://graph.facebook.com/page1'));
$fbsite2 = json_decode(file_get_contents('http://graph.facebook.com/page2'));
$fbsite3 = json_decode(file_get_contents('https://graph.facebook.com/page3'));
for($j=1; $j<=3; $j++){
$data[] = array(
'name' => ${'fbsite'.$j}->name,
'likes' => ${'fbsite'.$j}->likes,
'link' => ${'fbsite'.$j}->link
);
}
The problem is that this method requires an access token, which I'm not quite sure how to get. I've looked at the Facebook API reference, but there seems to be a few different access tokens (different permission etc.). Which one do I need to accomplish this? How do I get it?
If the pages are public, then you only need an app access token.
So create an app in the FB dev section (if you have not done so already), and then include your app access token in those request URLs:
http://graph.facebook.com/page1?access_token=…
FYI, you should consider requesting all that data in one go, instead of making multiple API requests. You can do that using this syntax (for up to 50 ids in one request),
http://graph.facebook.com/?ids=page1,page2,page3&access_token=…
And you will have to explicitly ask for the name, link and likes fields now (otherwise you will get name and id only):
http://graph.facebook.com/?ids=page1,page2,page3&fields=name,likes,link&access_token=…

how to post facebook user wall/ page status by a single user only no app install for other users

I am working on a site and i need to post page links from that site to a special user wall or page if something is published on it which means i only need one user to post that question.
the problem which i am facing is access token since i am not trying to show facebook login page in front of website traffic. its not like sharing on user wall we are basically trying to post status on a page automatically so any help for this problem will be appreciated.
i am using the following code which seems to work fine as long as the access token for the page is valid but i need to make something permanent so that i can add all the info in the php code hardcoded and it work for some weeks at-least without changing the api key or token
$appid = 'code';
$appsecret = 'code';
$wall= $pageId = 'code';
$token='page token';
$facebook = new Facebook(array('appId' => $appid, 'secret' => $appsecret, 'cookie' => true));
$params=array( 'message' => $msg,'name' => $title, 'caption' => $title, 'link' =>$uri,'description' => $desc, 'picture' => $pic, 'access_token' => $token,'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) );
$result = $facebook->api($wall.'/feed/','post',$params);
if i make token from the graph api debug page then it works fine but after some time i got the message "OAuthException: An active access token must be used to query information about the current user."
i am really desperate to find something solid for it.
thank you
You can write a backend script (maybe a cron job using the FB PHP-SDK) that runs as the special user and makes the desired FB api calls. For this, you will want to use a long-lived access token, which needs to be renewed every 60 days. You might also try your FB api calls using an App Access Token, which do not expire but also do not support all FB publishing and other operations.
To post to someones wall (or perform any action with the open graph) you must be authenticated with facebook as somebody in their graph or an application that they have granted permission to.
You should look at the permissions that can be set using the oauth scope attribute...
https://developers.facebook.com/docs/reference/dialogs/oauth/
To me it looks like they will need to grant your application publish_stream if you want to write to their friends walls as well as the user that you are authenticated as.
https://developers.facebook.com/docs/reference/login/extended-permissions/

Using Phonegap's Facebook access token on the server-side

I have Phonegap's Facebook plugin working perfectly within my Android app. This plugin uses Facebook's client-side Javascript flow. However, I would like to upload photos to FB from the server-side, instead of client-side, as this is much (much) more efficient.
Is it possible to use Facebook's access token generated from client-side on the server-side? (BTW, I have Facebook's PHP SDK working perfectly on stand alone web pages.)
I am getting a "(#200) Permissions Error" trying to pull this off.
If the client-side token cannot be used on the server, any other suggestions? I do not know of a way to generate a server-side Facebook token from a Phonegap app.
Edit:
It appears that you actually can use a client side Facebook token on the server. It's simple matter of upgrading to the latest Facebook PHP SDK, and using the $facebook->setAccessToken() function with a token sent from Javascript.
An access token is valid via client or server. On facebook end it is the same thing: a request through HTTP.
If you are not able to upload photos, check that you have the appropriate user permissions for your application.
If you are trying to figure out what graph api calls you need, a good starting place is the javascript console:
https://developers.facebook.com/tools/console/
Here you can see in the javascript what calls are being made in order to read fromt he api, or make a feed story or upload. You will use the same graph URLS and variables using server side code.
Yes you can use client side token in server side.Actually when user is logged into facebook ,fb create an access token in cookies ,which you can access on both client as well as server and when user is logged out ,cookie is destroyed and access token becomes invalid.
And to upload the photos to facebook i used following code :
// $friends is an array of friend id to be tagged in photo
// $x and $y are the position of tags.
for($i=0;$i<sizeof($friends);$i++)
{
$tags[] = array(
'tag_uid'=>$friends[$i],
'x' => $x[$i],
'y' => $y[$i],
);
}
$photo_details = array(
'access_token'=>$access_token ,
'message'=> 'Any message',
'tags' => $tags
);
$file=$photo_name; //Example image file
$photo_details['image'] = '#' . realpath($file);
$upload_photo = $facebook->api('/me/photos', 'post', $photo_details);

Change tab name facebook page

Is there a way to change the tab name of facebook page by
facebook graph API using PHP SDK. I think it is constant during
setup of facebook application.
after setting tab name of an application can I change tab name of facebook
page later by graph API.
Yes you can do this using the graph api.
First you have to get an access token for the page, to do this you will need to ask for the manage_pages permission.
Once you've initialized the PHP SDK to get the the page access token you make a call to...
$facebook->api('/THE_PAGE_ID?fields=access_token');
This returns an array like below
{
"access_token": "THE_PAGE_ACCESS_TOKEN",
"id": "THE_PAGE_ID",
"type": "page"
}
Before you use this token you may want to save the current users access token so you can set set it back again once you've finished doing the page stuff.
$users_access_token = $facebook->getAccessToken();
To then make the SDK use the page access token for the next call do
$facebook->setAccessToken('THE_PAGE_ACCESS_TOKEN');
Now we're ready to change the tab name by making a POST to /THE_PAGE_ID/tabs/TAB_ID with an array containing the new custom name
$this->api('/THE_PAGE_ID/tabs/TAB_ID', 'POST', array(
'custom_name' => 'THE_NEW_TAB_NAME'
));
TAB_ID should be the tab apps id prepended by app_
That should be it, don't forget to set the access token back to the users token before you try do anything non tab related
$facebook->setAccessToken($users_access_token);
It might be worth noting that you can use exactly the same process to change the tab position and set the default landing tab, you just need to add a couple of extra bits to the POST array, 'position' and 'is_non_connection_landing_tab'
$this->api('/THE_PAGE_ID/tabs/TAB_ID', 'POST', array(
'custom_name' => 'THE_NEW_TAB_NAME',
'position' => 1,
'is_non_connection_landing_tab' => true
));
Have a look here http://developers.facebook.com/docs/reference/api/page/ scroll down to Tabs. Graph api provides Read, Create, Update, Delete functionality.

Prevent signups with Facebook proxy email

Problem is, when a user clicks on FB Login button on my site, Facebook API throws him with a window which ask for access permissions(which is the usual flow). But when the user chooses the proxy mail address (anonymous), then I want to force the user to login only using his real email id.
How am I supposed to handle this ?
I can detect that user used proxy email and prevent him from registering, but then I can't remove my app from his list of authorized apps - meaning I can't get him to that initial dialog for choosing which email he will provide.
You can't force the user to go through the authorization dialog again, because as far as Facebook is concerned, the user has installed your application and nothing else needs to happen. The best thing you can do here is write your own form which informs the user that the Facebook proxy e-mail address is unacceptable and you need a real e-mail address. Unfortunately, this does not force the user to give you their Facebook account e-mail address, or even a real e-mail address. This is the best we have via Facebook though, and it's just something we have to deal with.
UPDATE 5/10/11
I was browsing around the Facebook documentation, and found a method that exists in the old Legacy REST API which actually allows you to remove extended permissions for your app from a user. I think you could use this exact API call to manage getting non-proxy addresses from your Facebook user, while still using the native install dialog.
I tested this using the FB JS SDK and it worked! The method you need to use is the auth.revokeExtendedPermission method. Here are 2 examples of calling that method via the JS SDK and the PHP SDK.
Javascript:
<script>
FB.api({
method: 'auth.revokeExtendedPermission',
perm: 'read_stream'
}, function(response)
{
console.log(response)
});
</script>
PHP:
<?php
$facebook->api(array(
'method' => 'auth.revokeExtendedPermission',
'perm' => 'email',
'uid' => $uid
));
Because these use the Legacy REST API they're not as "supported" as the new Graph API. I've not seen anything regarding migrating this feature to the Graph API. Hopefully they will.
Invoke revocation of the app through graph api (as below) with the php sdk then redirect user back through your dialog with this non-proxy requirement explained.
private function revokeAccess() {
$access_token = $this->facebook->getAccessToken();
$result = $this->facebook->api(array(
'method' => 'auth.revokeAuthorization',
'uid' => $this->{facebook id here},
'access_token' => $access_token
));
return $result;
}
This code is php.
This completely removes the app.
Returns 1 on success; 0 on failure.
$this->facebook == facebook object from the facebook php sdk.