Facebook Graph or signed_request to access the Page URL - php

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'];

Related

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.

Invite friends through Facebook, post to their wall and return to site

I have created an app for my site in Facebook. While inviting friends to the app, it returns a call back url:
> referrals/fb_invite?channel=6&ids[]=100000576230613
This leads to a 404 page error.
What does this URL mean from facebook and how can it be redirected to my site?
I think this is not an error from facebook.this might be happens only
from your side.
try to change the call back url and use the id retrieved from the facebook.
create the function fb_invite and use retrieved id and pass it.

facebook, how to get the facebook uid from any facebook page?

how to get the facebook uid off a page, when you visit that page?
if i go to a page of my friend or anybody, i need to know the uid. i can get mine like this:
$signed_request = $facebook->getSignedRequest();
$user_id = $signed_request['user_id'];
edit:
well i have this app and i need to pull the fakebook url into the application so i can grab the id from there.
if i try, i get the app id:
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
what i need is to grab the fb link address,like #Rufinus said, something like https://graph.facebook.com/cocacola
any ideas?
thanks
I'm still not 100% on what you're asking. It seems like you're definitely looking to get information about a page as opposed to a user.
If you have an app, on a page in a tab like on the coke page, then we'll pass you a signed request that contains the id of the page. You can then pass that to https://graph.facebook.com/{ID} and you'll get the same result as passing https://graph.facebook.com/{vanityUrl}.
What you want to access from the signed_request is $signed_request['page']['id'].
In that same page array, you can also pull ['page']['liked'] which will tell you if the viewer has liked the page. And finally you can access ['page']['admin'] which will tell you if the viewer is also an admin of that page.
If that doesn't answer your question, edit it a little more and i'll re-answer.
you just can call https://graph.facebook.com/cocacola no token needed.

Add Facebook Application to a fan page through API

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!

facebook graph api determine if user likes url

I want to display a different message if a user is currently logged in to facebook and likes the current page. I understand:
FB.Event.subscribe('edge.create', function(response) {
// you like this
});
Which will fire when a user likes the page, but when you reload the page how do you determine they already like the current page?
Thanks!
I'm pretty sure you cant do what you want (in this context).
Take a look at this page : http://fbrell.com/fb.api/does-like
You'll see you need the user to approve a permission to view the likes.
It's a huge security risk to allow someone to see the 'likes' of a user - even for the current page. Think about it you can easily spoof the current page and pretend to be any page.
BUT...
What I recommend you do is just set a cookie for your own benefit (in javascript) when the user 'Likes' your page. Assuming you're getting a large percentage of your 'Likes' from this page then you can safely correlate the presence of the cookie with a 'Like'.
I've seen some security exceptions doing this, but it seems to work (at least in Chrome).
Sense you describe the page as "current page" I understand that it is in an iframe tab. If this is the case, signed request supplies you with that information as $decode_signed_request = array('page' => array('liked' => true/false)).
Otherwise you can supply a canvas page with the GET parameters fb_page_id, which should include the parameter fb_sig_added to the server request with a 0/1 depending on if the user is a fan of that page. (This may require disabling OAuth 2.0 in your migration settings)
If you are talking about the like social plugin with an open graph url, you can not readily find out if the user is a fan without an application installation. If you do have that you can do an api call to /me/likes which will return a list of all the likes that user has, and search for the id of the object you are testing for.
You're safer using the Graph API since Facebook is in the process of deprecating their REST API. So to get if a user likes your page, you will need the page ID and the access token of your app.
https://graph.facebook.com/me/likes/PAGE_ID?format=json&access_token=ACCESS_TOKEN
Where PAGE_ID is the page id you want to check.
and ACCESS_TOKEN is your apps access token.
From the Graph API you can get the likes of a user by his id, as:
https://graph.facebook.com/ID/CONNECTION_TYPE
so for getting the likes you put your access token and:
https://graph.facebook.com/me/likes?access_token=2222222222222222
then look for your page if it is liked or not.
However you can always try FQL queries which i didnt try for Likes actually.
I hope that helped.
save user id or third_party_id in database when the user liked the link
to Get third_party_id
graph.facebook.com/me/?fields=third_party_id&access_token=xxx
https://graph.facebook.com/{FB_USER_ID}?fields=likes.target_id(167584559969748)&access_token={VALID_ACCESS_TOKEN}
shows data if that user has liked that Facebook fan page.
or
https://graph.facebook.com/{FB_USER_ID}?fields=likes.fields(link)
shows a list of liked links, from where you can get the link you are looking for.
All of these need 'user_likes' and/or friend_likes permissions.

Categories