I have to post on a facebook page, the titles of articles (with link) posted on a blog.
Unfortunately I can only post the link, but without the title. How can I do?
The PHP code I am using is this:
require ("facebook.php");
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXX',
'cookie' => true
));
// id page
$pageId = "136860079786056";
// permanent session token
$permSess = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// writing
$test = $facebook->api(array(
"uid" => $pageId,
"method" => "stream.publish",
"access_token" => $permSess,
"message" => "http://www.mysite.it/functions.php?p=view&id=31", ));
There is a link variable you can use for the link.
Eg
"link" => "http://google.com",
"message" => "The search engine we can't mention"
Related
I'm using FB App to publish posts to my FB pages.
So when i use this code for links, it works.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true
));
$attachment = array(
'access_token' => $row["token"],
'name' => $_POST["name"],
'picture' => $_POST["picture"],
'message' => $_POST["message"],
'link' => $_POST["link"]);
try
{
$facebook->api("/".$row['id']."/feed", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
But, when i want to share pictures as a page:
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
'fileUpload' => true,
'allowSignedRequest' => false
));
$attachment = array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message' => $_POST["message"]);
try
{
$facebook->api("/".$row['id']."/photos", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
The app post picture as user. USER to PAGE.
So i found that i need to use publish_pages permission, but my access token contains both publish_actions and publish_pages. I can't change that because I'm using one access token for a lot of things.
So i have to ask, is there a way to explicitly choose what permissions i want to use from access token. FB API have same code for page and user picture publish /user_id/photos and /page_id/photos.
Need to use Page access token, there's no other way.
I'm using PHP facebook API 3.2.3 to connect to facebook and publicate messages from my page.
Until recently it was working find, but now messages are not publicated.
When i copy returned by FB message ID to create link, it is there, but not on my facewall.
I can accesss to my message by link like this:
https://www.facebook.com/permalink.php?story_fbid=800134770033938&id=659754124150164
It says, that i've publicated link on my fanpage, but it is not visible on wall.
Ofcourse there are all necessary permissions.
Code looks like this:
$fb_fanpage_name = $fb['FBFanpageName'];
$fb_access_token = $fb['FBAccessToken'];
$fb_app_id = $fb['FBApp'];
$fb_secret = $fb['FBSecret'];
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => TRUE,
));
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url
);
try
{
$res = $facebook->api('/' . $fb_fanpage_name . '/links', 'post', $post);
} catch (Exception $e)
{
$this->zp($e->getMessage());
}
According to FB API on page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/links/ - you can't posting links like this.
Apparently You want post message to feed.
So to do this try :
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url,
'message' => 'try me!'
);
$facebook->api('/'. $fb_fanpage_name .'/feed', 'POST', $post);
Update : to find this look at page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed
i want to send notification who access my app.i use following code.
but it not work.i was goggling about it.but every example looks like my one.but it not work for me.
here is my code
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'myappsecret',
));
$app_id='myappid';
$app_secret='myappsecret';
$app_access_token=$app_id.'|'.$app_secret;
$user_id='359211054272153';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$response = $facebook->api( '/359211054272153/notifications', 'POST/v2.2/', array(
'template' => 'You have received a new message.',
'href' => 'RELATIVE URL',
'access_token' => $app_access_token
) );
i am used old version of Facebook sdk it want to real user id.
but currently
Facebook gives app scoped userid. thats the error.
using new sdk v4 it not problem.
how can i get the current logged in userid ?
im pretty sure my appId is correct
$facebook = new Facebook(array(
'appId' => '...',
'secret' => '...',
));
im using this method but i returns 0;
$facebook->getUser();
If you want to get facebook user id with this code
$facebook = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$user = $facebook->getUser();
You have condition to should have done before, the first condition is you put that code in the page that redirected after the user login via fb provide by this code
$params = array(
'display'=>'popup',
'redirect_uri' => 'http://example.com'
);
$loginUrl = $facebook->getLoginUrl($params);
OR the second condition is you already have the user 'Access Token', so the code will be like this
$facebook = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$facebook->setAccessToken('user_access_token');
$user = $facebook->getUser();
If you don't clear about the Facebook Login flow using PHP SDK, you can visit this page
$myData=$facebook->api('/me');
$myid=myData['id'];
$myName=myData['name'];
$myUsername=myData['username'];
[id] => your id
[name] => your full name
[first_name] => your firs name
[last_name] => lastname
[link] => profil link
[username] => username
[gender] => your gender (male,female)
[email] => your mail (if have email permission)
[timezone] => 2
[locale] => your locale
[verified] => 1
Follow this guide: Login for Server-side Apps. Basically, you have to generate a login URL, receive a code generated by Facebook, and with this code, request for an access token.
i am having a Problem posting a Picture in the Wall of an Event on Facebook.
It is Posting
My current Code is:
$post_array = array(
"access_token" => $facebook->getAccessToken(),
'source' => "#" . realpath("image.png"),
'message' => 'Some Message'
);
$post_id = $facebook->api("/".$event_id['id']."/feed", "POST", $post_array);
Everything is working fine, except for the Image: It won't be displayed.
Any Help out there?
If for Events, Try:
//Setup the Facebook object for file upload
$facebook = new Facebook(array(
'appId' => 'your_app_id_here',
'secret' => 'your_secret_here',
'cookie' => true,
'fileUpload' => true
));
Then:
$file = "image.png";
//The event information array (timestamps are "Facebook time"...)
$event_info = array(
"access_token' => 'your access token",
"name" => "Event Title",
"start_time" => 1290790800,
"end_time" => 1290799800,
"location" => "Your Location",
"description" => "Event Description"
);
$event_info[basename($file)] = '#' . realpath($file);
$result = $facebook->api('me/events','post',$event_info);
Hope it helps