Unsupported GET request when trying to fetch newly uploaded photo - php

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?

Related

Is it possible to post a photo to Facebook by a link, not upload?

Is this possible to create a photo on user/page's timeline not by uploading said photo, but by providing a URL to an already uploaded image? My code so far is this:
$response = $fb->api ("/$page_id/photos", 'post', array (
'name' => $_description,
'source' => $_image_path
));
This results in OAuthException #324 "Requires upload file". Also, I'd like to photo to be immediately posted on the page's timeline - will it happen, or do I need to make a separate call for that?
You can switch parameter source for url, and give it a publicly reachable HTTP URL as value.
But be aware, this only works for photos not on Facebook already – feeding it the URL of a photo on Facebook will result in an error message saying that posting photos from their CDN is not possible.

Facing problems while updating status using php sdk

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

Unexpected Error when posting photos to Test Users

I am experiencing a very strange error (could be a bug). I am trying to post a photo to a TEST USER. The first request I make goes through perfectly and the photo gets posted, but the 2nd, 3rd, etc. requests I make I get the following error:
"An unexpected error has occurred. Please retry your request later."
It is important to note that this is only an issue with TEST USERS. Normal users work perfectly for any number of requests. It is also important to note that this worked perfectly with TEST USERS for multiple requests about a week or two ago.
I am using the PHP SDK and post the photo using the following code:
// Create tag array
$tagArray = array(array('tag_uid' => $posterUid, 'x' => 0, 'y' => 0));
// Post the photo
$fb->setFileUploadSupport(true);
return $fb->api(
"/$posterUid/photos",
'POST',
array(
'access_token' => $accessToken,
'message' => $message,
'source' => '#' . $source,
'tags' => $tagArray
)
);
I have tried posting different photos and also tried deleting and recreating TEST USERS, but the problem persists.
I had a similar problem and it was driving me crazy. I was finally able to get it to work by turning off 'sandbox' mode on my developer application.
I have no idea why this made a difference. But it fixed the problem for me. Hope this helps someone.

Post image to Facebook fan page with PHP SDK

I am trying to upload a image to my fan pages wall using the PHP SDK, and also let other people upload pics to the page.
Here is what I have thus far,
PHP:
$img = realpath($y);
$facebook->setFileUploadSupport("http://" . $_SERVER['SERVER_NAME']);
$photo = $facebook->api('/FAN_PAGE_ALBUM_ID/photos', 'POST',
array(
'access_token' => $token,
'source' => '#' . $img,
'message' => 'This photo came from my app.'
)
);
When I try that nothing happens, even though I used a similar method to post to the fan pages wall, which worked fine, I also have the appropriate permissions, as far as I know... status_update,publish_stream,user_photos,offline_access ??
Any reason why this could be happening?
For you to be able to upload pictures to a page you are an administrator of, you would most likely need manage_pages permissions. I'm not sure you can have users upload pictures to a fan page from the graph api, although they can from the website so they should be able to.
You need this permission: manage_pages.

Facebook Photo Upload into Album on Fan Page failed

I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.

Categories