Facing problems while updating status using php sdk - php

I use following code to update the status:
$parameters = array(
'message' => "Hey guys check this cool app",
'link' => "http://apps.facebook.com/xxxx",
'name' => "Invitation for xxxx",
'picture'=>"http://localhost:55/xxxx/logo.jpg",
'caption' => "Try xxxx!",
'access_token'=>$at //valid access token
);
try{
$statusUpdate = $facebook->api('/me/feed', 'POST', $parameters);
}catch(FacebookApiException $e){}
This works and after status update, I get an id. But when i go to my profile and check the status update, This is what I see:
. The problems are: (1) Image is not displayed, and (2) Unwanted My first app as shown in figure. Why is this happening? How do i fix it?

http://localhost/... is never going to work as the image location because Facebook won't be able to retrieve it. Put the publicly accessible URL to the image in that field instead.
In the screenshot you posted, the 'My first app' part is the name of the app, you can change this in the app settings. It can't be changed on a per-post basis, all posts from your app are attributed to your app

As far as the image is concerned, check again that the path of the image is correct. If it still does not work, try specifying 'https' instead of http and see what happens

Related

Why is Facebook api Privacy parameters- custom - allow ignoring friend id's?

I am unable to allow specific user id's to see my uploaded photo via the privacy parameters. This is my code:
$privacy = array(
'value' => 'CUSTOM',
'allow' => '619211114855652',
);
$photo = (new FacebookRequest(
$session,
'PHOTO',
'/me/photos',
array (
'source' => new CURLFile ($location.$name),
'message' => ($caption),
'privacy' => json_encode ($privacy)
)
))->execute()->getGraphObject()->asArray();
The friend id is retrieved using the get /me/friend request but this is being ignored as when I run this, it sets to "only me" as my privacy setting. Having googled this, I found out that if CUSTOM and allow is not specified, it will by default set it to "only me" who can see the post. When I replace the id with "ALL_FRIENDS" it works. I really do not understand why it isn't working, I assume facebook is ignoring the id but I can't think why. Has anyone managed to set their privacy to specific users?
Also note, this does not override my max privacy settings of the app, as my max setting is set to "friends". And I am just trying to limit the friends who can see the post.
I've tested your code with a new application and I've found that it's the initial privacy setting you sent when adding the application causes this behaviour.
Go to Settings > Apps > Your App and change the "Visibility of App" setting to Friends or Public.
Then re-test your code and you'll see that it does indeed work work with a valid friend ID.
It was a bug. I reported it and now it works :)

Facebook ignoring og:image for shared website link

I have recently noticed that facebook has started ignoring my og:image tag on my site. The image used is always larger than 200x200.
Here is an example page:
http://bit.ly/15CrOhS
http://bit.ly/1b8Mgbe
Seems to be alot of questions, but no answers. I've added all the og information and checked with the linter and it all goes through fine. So why does it choose to pick a random image?
I use the facebook api for PHP to send:
<?php
$link = 'http://www.mylinkaddress.com';
$msg = 'Check out my new photo. '.$link;
$get_oauth = "SELECT * FROM users_oauth_cred WHERE userid = ".$_SESSION['userid']." AND share = 1 AND oauth_access_token != ''";
$get_oauth = mysql_query_run($get_oauth);
$oauth = mysql_fetch_array($get_oauth);
# FACEBOOK
$facebook = new Facebook(array(
'appId' => FACEBOOKAPPID,
'secret' => FACEBOOKSECRET,
'cookie' => false,
));
$token = $oauth['oauth_access_token'];
try {
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $token, 'message' => str_replace($link,'',$msg), 'link' => $link)
);
}
catch(FacebookApiException $e) {}
?>
I had the same issue.
Go to Facebook Object Debugger, verify every issue pointed there, fix them all. This solved my problem.
http://goo.gl/ASBsAa
Testing your query with the facebook Graph API Explorer worked fine for me.
You could try to add the additional parameter 'picture' to your post and place the link to your image in it.
So facebook is forced to use this as image in the post.
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $token, 'message' => str_replace($link,'',$msg), 'link' => $link, 'picture' => 'http://images.ephotozine.com/gallery/2011/49/normal/52194_1323334048.jpg')
);
Reading through all the comments here, I think what's happened is the following.
Let me know how close I got. This is a shot in the dark. ;)
The first time you shared a URL to Facebook, the og:image wasn't set up perfectly, and Facebook selected a random image on the page, and cached it.
You then fixed the og:image tag, and tried to check the same URL.. FB then regurgitated the cached image.
I tried with both your links just now, and everything seems fine.
:{D
Just be patient. Facebook needs some time to crawl this image. It will not immediately show up in Facebook. If your image is not showing up in some days, just drop a note here.
Much testing and trying other bulk uploaders etc. Finally just decided to email facebook with details and screnshot. next day the issue has been resolved. So, make sure to try that from the help email through your facebook account. worked for me.

Unsupported GET request when trying to fetch newly uploaded photo

I'm building a Facebook App where the user selects an image that gets uploaded to my App's album for that user. Everything works fine, the picture gets uploaded and posted on the user's wall etc no problems there.
But, after the upload I try to fetch the newly uploaded photo using the ID I get as a response from the upload, and this is where I run into problems. FB simply tells me "Unsupported GET request".
Here's the relevant code I have:
<?php
# Works perfectly fine
$response = $fb->api('/me/photos', 'post', array(
'message' => 'Some message',
'source' => '#' . realpath('path/to/img.jpg')
));
# "Unsupported GET request"... :/ (SOMETIMES ??)
$photo = $fb->api('/' . $response['id']);
All the authentication etc obviously works (otherwise I wouldn't be able to upload at all) it's just fetching the photo that does not work.
I'm using the PHP and JS SDK:s simultaneously and I've tried with both. I started with JS and it never worked. However, the PHP call works sometimes.
Does anyone know what I'm doing wrong?
Edit: Ok so I skipped fetching the newly created photo and instead simply constructed a URL to it using the ID returned from the upload (all I was after was the photo object's link property anyway - I figured it was more future proof to use instead of constructing your own). However, even now when I redirect to http://www.facebook.com/photo.php?fbid=ID_GOES_HERE&makeprofile=1 sometimes (again :P) Facebook will tell me the "content is not available". After a Ctrl+R, however, it is. This seems to me that FB hasn't finished adding the new content even though my $fb->api('/me/photos', 'post'...-call has returned an ID.
Thoughts?
Well for me, it was just because the method to post photo seems to change :
https://developers.facebook.com/docs/reference/api/page/#photos
$facebook->setFileUploadSupport(true);
$picture = "#".realpath('path/to/the/photo');
$result = $facebook->api(
'/fb_id_of_the_page/photos/',
'post',
array('access_token' => 'access_token',
'message' => 'message',
'source' => $picture
)
);
Well, pretty strange because the same thing happen to me.
Work fine and 12 hours ago, completely down. I can't post anymore whereas i've got return id.
When I ask the graph api with the return id I got this :
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
Just to notice it's happe only when I post image. With link or status everything is fine.
Is FB api in trouble?

Publish Feed To Facebook Jams Up PHP

I'm using the php SDK for the Graph API, and everything is working fine-getting usernames, uploading photos etc.
However, when I'm trying to publish to the current user's feed, it just makes the page get stuck.
This is the code:
$publish_feed = $facebook->api('/'.$userid'/feed', 'post', array(
'message'=> 'message',
'picture'=> 'http://mysubdomain.mywebsite.com/photo.jpg',
'link'=> 'http://apps.facebook.com/appname/'
););
I've tried:
Putting the code in different places in the code-no matter where I do, it gets the page stuck, Even if ti is at the end of the code, it gets it stuck, and nothing shows.
changing $userid to /me. No success.
Please help.
Make sure you have the publish_stream permission
use /me or api("/$userid/feed",..etc
Remove the extra column:
Code:
$params = array(
'message' => 'message',
'picture'=> 'http://mysubdomain.mywebsite.com/photo.jpg',
'link'=> 'http://apps.facebook.com/appname/'
);
$publish_feed = $facebook->api("/$userid/feed", "post", $params);

Facebook Open Graph - post to all approved users feeds

I'm struggling to get to grips with posting a feed item to all the members of an approved application.
Within the application settings for the user it is stating that the application has permission to post to the wall but I can only achieve this if that user is currently logged in to facebook. Obviously I would like this to function so that any items I uploaded are posted to all the members of the application at any one time.
I am using the Facebook PHP SDK from http://github.com/facebook/php-sdk/ and currrently my code is as follows:
require 'src/facebook.php';
//Generates access token for this transaction
$accessToken = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=MyAppId&client_secret=MySecret");
//Gets the full user details as an object
$contents = json_decode(file_get_contents("https://graph.facebook.com/SomeUserId?scope=publish_stream&" . $accessToken));
print_r($contents);
if ($facebook->api('/' . $contents->id . '/feed', 'POST',
array(
'title' => 'New and Improved, etc - 12/03/2010',
'link' => 'http://www.ib3.co.uk/news/2010/03/12/new-and-improved--etc',
'picture' => 'http://www.ib3.co.uk/userfiles/image/etc-booking.jpg',
'scope' => 'publish_stream'
)
)==TRUE) {
echo "message posted";
} else {
echo "message failed";
}
The output from $contents shows the expected user details but nothing relating to the permissions for my application. Am I missing a trick here?
Then using the $facebook->api() function I am receiving a
200 - Permissions error
. The application does not have permission to perform this action.
This is driving me a little potty as I suspect I'm missing something straightforward with the authorisation but what?
Many thanks in advance for an assistance offered.
I had the same problem yesterday. Finally I figured out that, although I had set checked the "permission to post to wall", I had to do this step also:
https://graph.facebook.com/oauth/authorize?client_id=XXXXXXX&scope=publish_stream&redirect=http://back.to.your.app/
There, the end-user will be served with the familiar Facebook "Allow this application to access your information?" dialog. After allowing, it will come back to your app, which then will have the proper permissions.
Hope this helps!

Categories