I'm building on a website for a client and the core functionality of it is to share photos with other users over Facebook.
So, what I've done is:
user picks a photo he likes and clicks the "share" button
script triggers Facebook "Friend Picker" popup
user picks a friend he wants to share the photo with and clicks "OK"
script triggers ajax request to the server which uploads the specific photo on the timeline of chosen friend
Here's the php photo sharing code:
$facebook = new Facebook($config);
$facebook->getAccessToken();
$user_id = $facebook->getUser();
$body = array(
'source' => '#' . CURR_DIR . $photo->path,
'message' => ''
);
if ($user_id)
{
try
{
$result = $facebook->api('/' . $fbid . '/photos', 'post', $body);
}
catch (FacebookApiException $e)
{
echo $e->getMessage();
}
}
So far this works beautifully, so my question is:
After the Facebook's "October 2013 breaking changes", they will be "removing the ability to post to friends' timelines via API".
They advise usage of feed dialog's from that point on.
So - how to upload a photo on a specific user's timeline using feed dialog's?
Is this even possible (because looking at the feed documentation page, I don't think it is...)?
So - how to upload a photo on a specific user's timeline using feed dialog's? Is this even possible
No, its not possible. I think you are now left with just one option- to post the photo on the user's wall (instead of friends'), and tag him/her on the photo. To tag friends, you have to use parameter: tags. Ref: Photo
Related
Im getting started with the php sdk, and struggling to understand a few things (I have a basic example below - but everytime the pic goes to MY wall and not the fan page)
Code:
require_once("facebook.php"); // set the right path
$config = array();
$config['appId'] = 'app id';
$config['secret'] = 'app secret';
$config['fileUpload'] = true; // optional
$fb = new Facebook($config);
$params = array(
// this is the access token for Fan Page
"access_token" => "I create this via the graph api (select App and click get token), I select publish stream and photo_upload permissions.",
"message" => "test message",
"source" => "#" ."photo.png", // "#" .
);
try {
// **** is Facebook id of Fan page
$ret = $fb->api('/****/photos', 'POST', $params);
echo 'Photo successfully uploaded to Facebook Album';
} catch(Exception $e) {
echo $e->getMessage();
}
the picture keeps going to MY wall (logged in user) and not the fan page, is that because im getting a token for the currently logged in user (me) instead of the fan page? and if so how do i generate a token for the fan page whilst logged in as the developer? (is it by putting the fan page id into the Get bar?)
Apologies for the noob questions but the facebook documentation sucks (until u understand the core functionality of course). Most tutorials work once u know how to use the graph API - none ive looked actually EXPLAIN how to use the graph to generate correct tokens, etc.
\POST /<ID>/photos — this will post on the <ID>'s wall only, so please double-check the <ID> that you are using.
The access token will depict that on behalf of whom the photo would be posted on the <ID>'s wall. If you use the user access token, the photo will be published on behalf of the user and if page access token is used, it will be published on the page's behalf itself.
You can get the page access token of your pages by-
\GET /me/accounts?fields=access_token
(permission required: manage_pages)
Demo
Sorry if this has been dealt with before, but my website guy is having issues getting this to work.
I am using facebook open graph api to post a testimonial from my PHP website CMS to my facebook business page.
I have a facebook profile and created a business page from my profile.
I have also created an app under my profile to get an app id and secret key which is used for the graph api to post on behalf of me from my website to my facebook businness page. The issue is I need the post to go directly to my business page and be posting as my business, not as or on behalf of me. Currently the api is sending the posts directly to my profile wall showing as me sharing a link via my business page and it doesn't appear on the business page at all. I need a way to post the testimonial to my business page directly rather than on my profile wall. How do I do that? My understanding is he has used the personal ID & App secret and also the business page app ID & secret, but seem to get the same result.
The code below is what is being used, any assistance would be greatly appreciated;
<?php
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'mysecrectkey',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try
{
$user_profile = $facebook->api('/me');
$AccessToken = $facebook->getAccessToken();
$data = array("message" => $pdes,"link" => "http://www.website.com.au/testimonial.php", "name" => $name);
$share = $facebook->api("/me/feed", "POST", $data);
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
?>
Well, your problem is here:
$share = $facebook->api("/me/feed", "POST", $data);
This code sends message to your wall, instead of the page. In order to post on your Facebook page on behalf of your page, first, your app needs to get manage_pages and publish_stream permissions. Once you have it you need to do is get the access token of the page you want to post on:
$pages = $facebook->api('/me/accounts');
foreach($pages as $page)
{
if($page['id'] == YOUR_PAGE_ID)
$data['access_token'] = $page['access_token'];
}
Once you have page access token you must use it to send message on your page's wall:
$facebook->api(YOUR_PAGE_ID . '/feed', 'POST', $data);
I know I cannot post through Facebook API messages to the user's wall with the links which go out of Facebook.
But can I post a message, where would be a link to a Facebook user? So far I didn't find something like that, so trying my luck here.
Using the /me/feed endpoint you can post to the user's wall, nothing prevents it.
You will need publish_stream permission.
if ($user) {
$attachment = array(
'message' => 'this is my message',
'link' => 'http://www.facebook.com/profile.php?id=xxxx',
);
try {
// Proceed knowing you have a user who is logged in and authenticated
$result = $facebook->api('/me/feed/','post',$attachment);
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
}
I know I cannot post through Facebook API messages to the user's wall
with the links which go out of Facebook.
You surely can, using the feed api
If the user have given you the permission to publish , you can post any link on his wall.
I am building an app where users can post a photo directly to their timeline from our app. We want to pre-populate it with some branded text and a link to the brand's Facebook page. For example, something like: "Check out my photo at XYZ event". And XYZ would be a link to http://facebook.com/xyz
The closest thing I can find is this: http://digitizor.com/2011/01/24/tag-user-facebook-graph/ but it would seem that this trick is no longer working.
We are using CURL to upload the photo to the users wall with the following array converted to a string for the CURLOPT_POSTFIELDS:
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
$fields = array(
'url'=>"http://" . $imgPath,
'message'=>urlencode(stripslashes($_POST['message'] . " #[$brandFBUID:1:$brandName]" )) );
I'm looking to integrate my current website more deeply with Facebook using a Fan Page (notice: I did noticed the Open Graph protocol that Facebook support but i'm looking to create a website-wide fan page).
I know that you can create and manage Fan Pages using Facebook, but I'm looking for a way to do that using a PHP script - for example, post to the Fan Page wall, create events using the Fan Page and ideally - create secondary Fan Pages on the fly.
After looking around in Facebook's developer section I didn't find a method to do those tasks from outside using the Facebook API.
So my question is: how would you accomplish that?
Thanks!
Publishing posts to your Page, and creating Events, are both relatively trivial tasks. You can use the Graph API to do that.
Check out the area about Publishing specifically. It gives you the general overview of how publishing works, and this can be applied all over the Graph.
Also, the documentation about the Events portion of the Graph API has an example cURL post for how to create a new event via the Graph API.
Posting anything to your Facebook page is going to require you have the manage_pages extended permission, and it's probably a good idea to get the offline_access permission also.
An example of both posting to your Page wall and creating an event (in php) would look a lot like this:
<?php
require 'facebook.php';
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true
));
$your_page_id = '123123123';
//get the access token to post to your page via the graph api
$accounts = $fb->api("/me/accounts");
foreach ($accounts['data'] as $account)
{
if ($account['id'] == $your_page_id)
{
//found the access token, now we can break out of the loop
$page_access_token = $account['access_token'];
break;
}
}
try
{
//publish a story to the page's wall (as the page)
$post_id = $fb->api("/{$your_page_id}/feed", "POST", array(
'message' => "Hello to all my fans, I love you!"
'access_token' => $page_access_token;
));
echo "Post published. ID: {$post_id}<br>";
//create a new event.
$event_id = $fb->api("/{$your_page_id}/events", "POST", array(
"name" => "My Totally Awesome Event, You Better Show UP!",
"start_time" => time(), //it starts now...duh!
"location" => "Anywhere, USA"
));
echo echo "Event created. ID: {$event_id}<br>";
}
catch (Exception $e)
{
var_dump($e);
}
As for creating Pages on the fly, the only way you can do that is by using the Open Graph Protocol. The only restriction here is that pages have to have unique URLS. So you can assign each of your Open Graph objects a unique ID, and give them a URL like http://www.mysite.com/pages?id=123456. This will let you output the Open Graph tags required to generate the page on FB. You can then use the Graph API to get the ID of the Open Graph object after someone likes it like so: http://graph.facebook.com/?ids=http://www.mysite.com/pages?id=123456.
You can publish to these Open Graph objects the same exact way you'd publish to a standard Facebook Page.
Hope that helps!