use facebook privacy on external sites - php

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.

Related

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.

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

get facebook user-id/username to fetch profile picture without Facebook SDK? PHP

I'm looking for a way to get a users facebook profile id or username which i can use to get the profile picture based on the users account. I know how to fetch the picture already (http://graph.facebook.com/username_or_id/picture). I don't want to ask the user to submit their fb username (or worse - their profile id), i need it all done automatically (happy user).
Now i have not setup a Facebook app to use the facebook SDK so i don't have a appID or a secret code...
The reason for not setting it up is because im working on something that not only i will use. It's a project where others will be able to use on their own domain and i don't want to ask the users to setup their own FB app just to get this working so im looking for a way to do it, without the FB SDK? or have i got it all wrong?
You can do everything without FB SDK (it's just a library), but you can do nothing without application. So no, you can't get user's ID without their knowledge

facebook permissions request without login button

I started a new facebook app with php-sdk 3.0 and I have a problem :
when the user comes on the app for the first time, he gets a page with just the facebook logo and a link "access facebook.com" even if the user is already connected to facebook ...
how can I skip this step ? without previous sdk , I was able to go the permissions request screen directly ?
The dreaded facebook blue box of death. It sounds like you're trying to do a redirect inside the app; try using javascript to do window.top.location.href = url; instead.
First I have a question to clarify. Then some possible answers based on some assumptions about your question.
Are you writing a Website with Facebook integrated, or an App for facebook?
Im going to assume you are writing a website with facebook integration. If you look at the example that came with the new API you can see they are using
$facebook->getUser();
This attempts to get the facebook User. You can get a facebook user, but they may not have a valid FB session, so to check this you want to use.
$facebook->api('/me/home');
If this returns information instead of an exception you have a user with a valid session.
At this point attempting, using php's header() function you can redirect them to the page given to you by $facebook->getLoginUrl(); and they should just be taken to the permissions window and not required to log in.
However, If you do not check for a valid user before you attempt to get the login url im pretty sure the api assumes that there is no one logged in and forces them to the log in page first.
If on the other hand you are talking about creating an App for Facebook itself, I think the original poster had the proper answer.

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!

Categories