Facebook Photo Upload into Album on Fan Page failed - php

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.

Related

Facebook PHP - posting error to timeline but not to page

I am trying to post to a Facebook account (with permissions) using the PHP
API. I am giving our users two options - posting to the Feed, and posting
to a specific facebook page. I am getting an error in the first case, but
not in the second case. In the code below:
$access_token is the access token I got back from linking to my app. It's of type
"User", and has the following permissions:
email
pages_show_list
business_management
pages_read_engagement
pages_manage_metadata
pages_read_user_content
pages_manage_ads
pages_manage_posts
pages_manage_engagement
public_profile
Where $page_token is, well, a "Page" type token, with the same set of permissions.
When I post to the page, it works fine. But when I try to post to the timeline, I get
the error:
Graph Error 200 : [Timeline]: [(#200) If posting to a group, requires app being
installed in the group, and either publish_to_groups permission with user token,
or both pages_read_engagement and pages_manage_posts permission with page token;
If posting to a page, requires both pages_read_engagement and pages_manage_posts
as an admin with sufficient administrative permission]
I'm not trying to post to a group, I'm posting to an account's timeline. And, per the
access token debugger, I have the permissions requested anyway. What's going on?
My code is below:
$linkData = [
'link' => $link_to_post,
'appsecret_proof' => $app_secret_proof
];
if ( POSTING TO TIMELINE )
{
$token = $access_token;
$post_to = "/me/feed";
}
else
{
$page_id = $page_id;
$token = $page_token;
$post_to = "/$page_id/feed";
}
// THIS THROWS THE EXCEPTION:
$response = $this->fb->post($post_to, $linkData, $token);
You can not post to a personal timeline via API any more, that was removed ages ago already. (With introduction of API v2.4, if I remember correctly.)
You can only use the Share or the Feed dialog, to offer the user a way to actively share / make a post themselves, https://developers.facebook.com/docs/sharing/web

unable to retrieve picasa photos with php when requesting data feed

I tried to retrieve the latest 10 photos from my picasa account but it doesn't work.
$file = file_get_contents("http://picasaweb.google.com/data/feed/api/user/firdawsfm?kind=photo&max-results=10&alt=json&access=public&thumbsize=".$tSize);
print_r($file);
the result :
{"$t":"http://picasaweb.google.com/data/feed/api/user/firdawsfm"},"updated":{"$t":"2013-09-08T19:27:11.010Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind",
"term":"http://schemas.google.com/photos/2007#user"}],
"title":{"$t":"108451527358440546192","type":"text"},
"subtitle":{"$t":"","type":"text"},
"icon":{"$t":"http://lh3.ggpht.com/-Srl88atqmQE/AAAAAAAAAAI/AAAAAAAAAAA/AhcCTIASEAM/s64-c/108451527358440546192.jpg"},
"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml",
"href":"http://picasaweb.google.com/data/feed/api/user/108451527358440546192?alt=json"},{"rel":"alternate",
"type":"text/html",
"href":"https://picasaweb.google.com/108451527358440546192"},{"rel":"http://schemas.google.com/photos/2007#slideshow",
"type":"application/x-shockwave-flash",
"href":"https://static.googleusercontent.com/external_content/picasaweb.googleusercontent.com/slideshow.swf?host=picasaweb.google.com&RGB=0x000000&feed=http://picasaweb.google.com/data/feed/api/user/108451527358440546192?alt%3Drss"},{"rel":"self","type":"application/atom+xml",
"href":"http://picasaweb.google.com/data/feed/api/user/108451527358440546192?alt=json&q=&start-index=1&max-results=10&kind=photo&thumbsize=180c&access=public"}],
"author":[{"name":{"$t":"Firdaws Haskell"},"uri":{"$t":"https://picasaweb.google.com/108451527358440546192"}}],
"generator":{"$t":"Picasaweb",
"version":"1.00",
"uri":"http://picasaweb.google.com/"},
"openSearch$totalResults":{"$t":0},
"openSearch$startIndex":{"$t":1},"openSearch$itemsPerPage":{"$t":10},
"gphoto$user":{"$t":"108451527358440546192"},"gphoto$nickname":{"$t":"Firdaws Haskell"},"gphoto$thumbnail":{"$t":"http://lh3.ggpht.com/-Srl88atqmQE/AAAAAAAAAAI/AAAAAAAAAAA/AhcCTIASEAM/s64-c/108451527358440546192.jpg"}}}
there is no data about photos. when I tried this exemple with another account it works. I verified the photos are public.
I tried your url and all works fine, i can access gphoti$id and media$group values.
So far seems all ok ;) Try again!
Maybe you didn`t have public photos at that time there...
Not relevant answer to that question
(in case if server requests authorisation):
For all Picasa web albums api queries with alt=json, or alt=json-in-code and /userid/default/ you must provide access_token parameter.
Access token you can get using OAuth2 authorization work-flow as described here:
http://code.google.com/p/google-api-php-client/wiki/OAuth2 (using google-api-php-client SDK for example)
And using in scopes this value "http://picasaweb.google.com/data/".
More how to do OAuth2 and get access token from https://accounts.google.com/o/oauth2/token
after requesting user login: https://accounts.google.com/o/oauth2/auth you can find on official website:
https://developers.google.com/accounts/docs/OAuth2Login
In final you must have:
$file = file_get_contents("http://picasaweb.google.com/data/feed/api/user/firdawsfm?kind=photo&max-results=10&alt=json&access=public&thumbsize=".$tSize."&access_token=".$access_token);
print_r($file);

Post to facebook page on behalf of user who is not a page admin

We are trying to build a facebook application that posts a message from a user to a facebook business page (which the user is NOT an admin of.) We need the post to be from the USER, not the page or the page admin. We are using the facebook PHP SDK and so far have accomplished getting the user's message to post to their own feed. (Using an App Access Token.) Though when we try to post the message to the facebook page (not owned by the user) we get this error:
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in
Is it possible to post to a facebook page, not owned by the user on behalf of the user? We are admins on the facebook page, but if we post using the Page Access Token then the post is no longer authored by the user, but instead the facebook page or page admin.
Here is a snippet of our code to see how we're going about this:
Posting to user's feed as user (works)
$fbpage = "/$fbid/feed";
$attachment = array(
'message' => $msg,'from' => array('name' => $name,'id' => $fbid));
$result = $facebook->api('/'.$fbpage.'?access_token='.$accesstoken, 'post', $attachment);
Posting to facebook page as user (doesn't work)
$fbpage = "/johnsjoint/feed";
$attachment = array('message' => $msg,'from' => array('name' => $name,'id' => $fbid));
$result = $facebook->api('/'.$fbpage.'?access_token='.$accesstoken, 'post', $attachment);
After a lot of research, it appears that this isn't possible. If anyone knows otherwise, please post here.
Not sure if its the exact same issue, but this might shed a light over your problem. See
"Posting to Facebook fan page feed as user through PHP SDK"

Access to page's photo albums from within web app using tokens?

Im using Facebook's PHP sdk for the first time in a clients site and I'm a little confused. I'm trying to get some data from the clients facebook page and inject it into their site. One of the objects I am trying to get is a list of the clients photo albums for a photo gallery.
<?php
$albums = $Facebook->api("/169639127532/albums?fields=id,name,cover_photo");
$photos = array();
$queries = array();
foreach($albums['data'] as $album) {
if(array_key_exists("cover_photo", $album))
$queries[] = array("method" => "GET", "relative_url" => "/".$album['cover_photo']."?fields=source");
}
$rawPhotos = $Facebook->api('?batch='.json_encode($queries), 'POST');
foreach($rawPhotos as $photo) {
//print_r(json_decode($photo['body'])); echo "<br /><br />";
$photo = json_decode($photo['body']);
$photos[$photo->id] = $photo->source;
}
As you can see, im getting a list of the albums, then using a batch request to get all the cover photos for those albums.
Using my clients page ID, this doesn't work, nothing is returned. However if I use another page's ID this works.
So I put this down to authorisation. I noticed that if I used the Graph API explorer with an access token I could get the photos. Because of this, I copied the Token I had generated with the API explorer, and set it globally on the site using the following function and this works.
$Facebook->setAccessToken($token)
Obivously this isn't a very robust solution as the tokens only exist for a finite amount of time. I tried getting a token for the app using the /oauth/access_token API call with my apps details and successfully got a token back. If I use this as the token I can no longer see the data I was getting with the temporary token from the graph explorer however.
I do not want users to have to login just in order to see the photo gallery on the site.
How do I go about getting a token for the app that would allow me to do this?
Thanks.

facebook api post to wall

I currently am able to post to a users wall however I would like the post to give a preview since what im posting is a link...
To explain myself better If i was to log into my facebook account and copy a link and paste it to my wall it displays an audio player (all the meta data is already configured, tested and working) however, using code to post this same link it doesnt show the audio player instead it only shows the link to click on. Is there a way i can make facebook display the audio player...?
Heres the code im using to post:
$fbResult = $facebook->api(
'/' . $userId . '/feed/',
'post',
array('access_token' => $access_token, 'message' => $url)
);
Thanks in advance for the help!
I’m assuming you’re posting the URL as part of your message parameter?
Do it by explicitly using the link parameter for the URL.
https://developers.facebook.com/docs/reference/api/user/#links

Categories