Access non-friends profile updates using php - facebook

Is it possible to access profile updates of a facebook user who is not in your(application authorizer) friend list or like-list?
For example:
http://www.facebook.com/zuck
or
http://www.facebook.com/mashable
Is it possible using facebook api?

It depends on their privacy settings

<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
));
$username = isset($_GET['username'])?$_GET['username']:"johnbevere.page";
$profile = $facebook->api('/'.$username.'/posts');
?>
<br/><br/><img src="https://graph.facebook.com/<?=$username?>/picture">
<?php
foreach( $profile['data'] as $data ){
if($data['message']){
echo $data['message']."<br><hr><br>";
}else{
echo $data['story']."<br><hr><br>";
}
}
?>
Success:
Page updates
User timeline Activity Log
Failed:
User timeline Feed
It is not possible to scrap the public feed of random profile using facebook API

Related

is it possible to post facebook page wall using a cron job?

Please don't vote and flag this quest. Please.
I am is the admin of the page. How can I post to that page wall using php SDK.
Is it possible or not?
the following code is posting as I post the page. I want the page itself post things to the wall.
<?php
include_once("inc/facebook.php"); //include facebook SDK
######### edit details ##########
$appId = '1157979879888106'; //Facebook App ID
$appSecret = '86403d4061433e23a0ouo9ec46a1405'; // Facebook App Secret
$return_url = 'http://xxxx.com/site/test'; //return url (url to script)
$homeurl = 'http://xxxx.com/site/index'; //return to home
$fbPermissions = 'publish_stream,manage_pages'; //Required facebook permissions
##################################
$page_id = "447126725331764";
//Call Facebook API
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret
));
//$fbuser = $facebook->getUser();
$publish = $facebook->api('/'.$page_id.'/feed', 'post',
array('access_token' => 'CAAQdLHAnOgoBAGAYZCIE09nfXaWZBXdMuwW5I379TjaWMZAQSUZCks9B4JfQyMXBEDN1CQZBaQJFeP44vWTGhic8AnkBgARge0AKJHIYgMdfDk16rq6ON496t0Phv6QtCmOR7t3wcybioNjxFkYctuN1ppDEBQdAObi6eIva0ZBTvAHJOWCSfcNicaVIZD',
'message'=> "Hello boss",
'from' => $appId,
'to' => $page_id,
'caption' => 'Caption',
'name' => 'Name',
'link' => 'http://www.example.com/',
'picture' => 'http://www.phpgang.com/wp-content/themes/PHPGang_v2/img/logo.png',
'description' => 'Hello boss'.' via demo.PHPGang.com'
));
?>
First of all, publish_stream is deprecated since many years. You really need to check out the Facebook docs, they state clearly that you need publish_pages and manage_pages to post "as Page".
That being said, that exact same question gets asked a LOT on Stackoverflow, so you can easily find a lot more information with the search function. In general, this is what you need to do:
Authorize the user with publish_pages and manage_pages
(Generate an Extended User Token)
Get a Page Token with /me/accounts
User that Page Token to post to the Page wall
More information about Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Facebook PHP SDK: getAccessToken not correct on refresh

On my facebook app, I'm logging a user in using the Javascript SDK.
If OK, I redirect him to this PHP page (designed to illustrate my problem):
test.php:
<?php
include('config.php');
require('phpsdk.php');
$access_token = $facebook->getAccessToken();
echo $access_token;
echo "<br /><br />";
$user = $facebook->getUser();
echo $user;
?>
(phpsdk.php handels the PHP SDK initiation)
Accessing test.php the FIRST time, returns a valid access token and the ID of the logged user.
However, when I refresh the page, the access token becomes of the type appID|appSecret.
The user is still logged in: getUser still returns the correct user ID.
Anyone knows what's causing this?
Clearing the Facebook Session with php sdk in redirect when user logs out.
Logout.php redirect user and use sdk to clear session data.
example redirect url. yourdomain.com/Logout.php?destroy=true
refer to: https://developers.facebook.com/docs/reference/php/facebook-destroySession/
<?php
session_start();
require './src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'appID',
'secret' => 'appSecret',
'cookie' => true, // enable optional cookie support
));
if(isset($_GET['destroy'])){
$facebook->destroySession();
}
?>
It is not recommended to call getAccessToken(); over and over the way you described.
You should try first to see if the token is in the browser as a session and if not then try to use the SDK to find or request it.
Check browser for a user, if no user call sdk for user, if still null or 0 auth or reauth.
If user, check browser for access_token, if no token call sdk for token.
<?php
session_start();
include('config.php');
require('phpsdk.php');
// need to replace Your_App_ID and YourAppId with your applications id.
$facebook = new Facebook(array(
'appId' => 'Your_App_ID',
'secret' => 'Your_App_Secret',
'cookie' => true, // enable optional cookie support
));
if(isset($_SESSION['fb_YourAppId_user_id'])){
$user = $_SESSION['fb_YourAppId_user_id'];
}else{
$user = $facebook->getUser();
}
if($user){
if(isset($_SESSION['fb_YourAppId_access_token'])){
$access_token = $_SESSION['fb_YourAppId_access_token'];
}else{
$access_token = $facebook->getAccessToken();
}
}
echo $user;
echo "<br /><br />";
echo $access_token;
?>

how can we invite friends on fanpage to like page?

i am creating a fanpage and attach in my facebook apps.
i want to invite my friends form my facebook page to like page and get some offer
so i am using code to display status.
<?php
require 'facebook.php';
$app_id = "xxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
?>
here using facebook api to get pageid or user id and other information .
There is no API which allows you to invite a user to like a page, this is only available in Facebook's frontend
I have the same issue but I intend to use (Requests)
https://developers.facebook.com/docs/reference/dialogs/requests/
You can send their friends a request asking them to like your page ! I guess this is more effective and you decide what should be written in the request!

Facebook - retrieve user info using ID

In my database I have facebook ID-s of users of my App.
Now I need to retrieve these users in PHP.
I use this:
$json=file_get_contents("http://graph.facebook.com/UID");
$fdata=json_decode($json);
$fname=$fdata->name;
echo '<img src="https://graph.facebook.com/'.$row['uid'].'/picture">';
echo '$fname';
I need to put this code into WHILE.. I already retrieve users photos using UID, but I also need names. As I understand I should write something Like this:
while($row = mysql_fetch_array($result)){
$json=file_get_contents("http://graph.facebook.com/$row['uid']");
$fdata=json_decode($json);
$fname=$fdata->name;
echo $row['uid'];
echo '<img src="https://graph.facebook.com/'.$row['uid'].'/picture">';
echo "<br>";
}
But it doesn't work. What I'm doing wrong??
Thanks in advance!
Use the official PHP SDK for Facebook.
https://github.com/facebook/php-sdk/tree/master/src
Then call:
$fb = new Facebook(array(
'appId' => <app_id>,
'secret' => <app_secret>,
'cookie' => true
));
Then use the api, like:
$varfordata = $fb->api();
A good site for searching: http://fbdevwiki.com/wiki/

Extended Permissions on Facebook Graph API in PHP

I am trying to write an app using the most recent Facebook PHP SDK. However, any extended permissions I request are simply not requested, it always defaults to the basic request, and does not ask for any of the requested extended permissions.
Here is how I am requesting these permissions:
<?php
require_once("facebook.php");
$app_id = "xxx";
$app_secret = "xxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
if(is_null($facebook->getUser())){
$params = array(‘scope’ => ‘user_status,publish_stream,user_photos’);
header("Location:{$facebook->getLoginUrl($params)}");
exit;
}
?>
This file is included at the beginning of any page on which my app is embedded. Any ideas as to why I don't get the extended permissions I want?
Make sure you are using quotes '. It seems that you copied this example from a page or something.
if(is_null($facebook->getUser())){
$params = array('req_perms' => 'user_status,publish_stream,user_photos');
header("Location:{$facebook->getLoginUrl($params)}");
exit;
}
UPDATE: use scope instead of req_perms with the new SDK.
You should pass the 'scope' parameter in a comma separated array.