Add Facebook Application to a fan page through API - php

Is there a way to add a facebook application to a tab in a fan page through API?
I have developed an app.When a user go to the app I need to display the admin fan pages of the user and ask him to select a page.When a user select a page and click "Add" button, I want to add application into a tab in selected fanpage.
I know how to get admin fan pages of the user using api.And also I know to detect when my app is running through a fanpage using 'signed request'.
So can anyone please tell me is there a way to add a facebook application to a fan page through API?

Found the solution
It just a straightforward process.I Just had to use this link(Doesn't need to call api)
When a user access the app(Not through a fanpage.Can detect when a app is running through a fanpage using 'signed request'.) user should derected to this link,
<script>
top.location = 'http://www.facebook.com/add.php?api_key=YOUR_APP_ID&pages=1';
</script>
It will display the facebook window with all admin pages of the user asking him to add app into a tab in his fan page.

actually, it appears there is a way by using the fb api, which saves the round trip to facebook and back.
the answer is awkwardly situated in the page object page reference (under "tabs"->create)
https://developers.facebook.com/docs/reference/api/page/
you need to make this kind of call to the api:
$appId = YOUR_APP_ID;
$pageId = THE_PAGE_TO_ADD_TO;
$apiUrl = "/".$pageId."/tabs";
$addedToPage = $this->facebook->api($apiUrl, "post", array("app_id"=>$appId));
good luck!

Related

Is it possible to add a post on a facebook page via the graph API without a Facebook App?

I want to post updates automatically to my facebook page from my PHP website.
Facebook seems to force me to create an App where users can login and then post stuff.
But I don´t need all that stuff, I just want to post to the facebook page directly via code.
I went "Ok, I´ll create an App", but now for them to give my app the needed permissions, they want me to give them a login so they can test my app and stuff ... Is there no simple way to just autopost something to my own Facebook page?

Use facebook sharer.php to share on a page wall

I want to link a user to make a share post on my fb company page without having to authenticate. Currently I can get them to share on their own wall with:
But I'm not sure how I can get this to share to a page's wall rather than their timeline.
I got somewhat close by using the dialog feature:
https://www.facebook.com/dialog/feed?app_id=xxx&link=xxx&picture=xxx&name=xxx&caption=xxx&description=xxx&redirect_uri=xxx
But that just showed it as a normal share but done "via appName", unless there is a step I'm missing to link my app to my facebook page?
Thank you!
Unfortunately, the sharer.php method is used only to share only on the user's timeline.
If you want to ask the user to post on a page's timeline, you have to create an app, ask the user to authenticate it and then use the Facebook APIs to post on their behalf. I guess that will be cumbersome in your case, so I would just suggest you redirect to the particular Facebook page.
You can't !
To publish on YOUR page timeline, users need to have the rights to do it (be admin, writer, ...) : it's a manual requirement on the Facebook interface.

use facebook privacy on external sites

I'm not sure if the title fits.
Let me describe what I'm thinking.
I'm not familiar with facebook API.
You see, I have this page on a site. And I want this page to be visible only for my friends on facebook. Is there a way I could do that? Like send error 404 if the one viewing is not logged in or not my friend on facebook.
Yes it is possible, just make that page to accessed through a script which contains code to get facebook access token and user facebook ID if there is access token & FB ID than redirect user on the page you wants to display only for your friend. In that page first match the obtained facebook id with the ids of your friends(either stored in db using facebook api). If ids matches with the stored one than load your script other wise redirect it to a 404 html page or to some other url want to show.
Yes this is very much possible.
You need to make your website and add its URL to a facebook app
(very easy to create a facebook app , just go to the facebook developers and follow the instrcutions).
after u create an app
All you need to do is redirect the user to an OAuth Dialog which will ask the user to accept and add the application giving you the users details.
Here is a simple tutorial to do so https://developers.facebook.com/docs/reference/dialogs/oauth/
after the user accepts it he will be redirected to a URL which u will have to specify (see the tutorial)
or you can do this :
use the facebook php sdk and access the user info this way
https://developers.facebook.com/docs/php/howto/profilewithgraphapi/
In both ways u get the user details and then u can check them against your friends profile details and only allow those users who match it and redirect the rest of the users to any other page using the header("any.url.com"); command of php.
If u still don't get it please tell me and i will elaborate more.
Yes this is possible
The obvious way would be using the facebook SDK make your friends log in, But that requires an active log in on your site. Once they are logged in its easy to see if they are on your friends list.
A less obvious way is using something described here
http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/
but combining with your profile in a way which if you get an ok reply (200 status code) on an image you only share with friends, Then have a call back to load another page.
This ISNT foolproof as you rely on javascript not being tampered with but requires less activity from the user
create a Facebook app, go to the App Dashboard, click the '+ Create New App' button.
give your website URL to Canvas URL*
now you are ready to user facebook API
require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$facebook = new Facebook($config);
var_dump($facebook);
* There are 2 way to do this.

Facebook Graph or signed_request to access the Page URL

I wonder if someone can answer this;
I have a canvas app, which in turn allows the user of the app to attach another app into their page tab. Everything works great. The page tab is now running from the users account.
If a 'Viewer' interacts with that app on the users page tab, i know I cannot get their user id, but how can I get the actual URL of that page they are on, so I can update Pinterest for the 'Viewer'.
Some people state that I need to access the signed request and some say the graph for the Page ID. Which one is the correct way to get the Page ID, or does it even matter ?
Thank you
Take in account that your app always will receive the signed_request var from FB. So why don't use it? Using php-sdk you can obtain it like this:
$signed_request = $facebook->getSignedRequest();
// so for the page ID you do:
$page_id = $signed_request['page']['id'];

Add Facebook status feed to profile page of site members

I have a Digg style site, currently each member has a profile page where they add links to their projects and social networking profiles.
I am trying to implement a feature that allows the member to display the last "X" number of status updates to their Facebook wall.
I have been going through the Facebook API FAQs, but unclear on how to best implement this.
Does anyone know a good starting point for writing the API call or where I should look for examples?
My site currently runs on PHP.
Here's a set of point to get you started:
Create an application
Download the Facebook PHP-SDK
Acquire the read_stream,offline_access permissions (more about this here)
Save the user id AND the access_token to your DB.
Next time you want to retrieve the user's wall posts use:
$feed = $facebook->api("/PROFILE_ID/feed", "GET", array("access_token" => "XXXX"));
Always try your Facebook application locally before implementing it on a live website (see link on point 3).

Categories