Using graph api to obtain a direct link on page feed - facebook-graph-api

I have now tried a lot of combinations, but I fail to reproduce the same result as obtained when posting manually:
I want to post a link to a facebook page I have created (not to the user wall). I do this by obtaining the page access token:
$page_access = $facebook->api('/'.$pageid.'?fields=access_token');
Then I set (before posting):
$facebook->setAccessToken($page_access['access_token']);
Finally my post is:
$attachment = array('message' => 'this is my link',
'link' => 'http://www.facebook.com'
;
$sendMessage = $facebook->api('/'.$pageid.'/feed/','post',$attachment);
I have also tried setting the name, link and description fields in the $attachment structure, but the published result always includes a link of the type:
https://www.facebook.com/connect/uiserver.php?app_id=_my_app_id&method=permissions.request&redirect_uri=http%3A%2F%2Fwww.facebook.com%2F&response_type=code&display=async&auth_referral=1
instead of the direct link to http://www.facebook.com. However, if I post the link manually I get a direct link (this is what I want) and also a "Share" action.
So my question: How do I convince the api to publish the link as is, and also get a "Share" action?

The reason your app is not posting a direct link is because you have Authenticated Referrals enabled on your application. This means Facebook always tries to get the user to Connect to your links before they are redirected to the link.
Try disabling Authenticated Referrals and see if it makes a difference.

Related

Get comments of public facebook post

I'm trying to download every comment on a public facebook post (it's one of those "can you do this basic algebra problem" posts - I want to see what percent of the comments get it right).
The Graph API Reference shows that I should be able to just GET graph.facebook.com/v2.5/{object-id}/comments.
I believe the object-id of this post is {user-id}_{post-id}, where post-id is the id in the url. So given this url:
https://www.facebook.com/beth.mansfield.9/posts/10207885721596563
The user-id of facebook.com/beth.mansfield.9 is 1101752663 (from findmyfbid.com), and the post-id is 10207885721596563 (from the url), which makes the object-id="1101752663_10207885721596563".
When I try graph.facebook.com/v2.5/1101752663_10207885721596563/comments in the Graph API Explorer, though, I get:
{
"data": [
]
}
What am I doing wrong? Is there another way to get the comments? There are close to a million so loading them all in the browser and scraping with javascript would be unfeasible.
That is a user profile. You can only get data of a user profile if that specific user authorized your App. In that case, you would need to authorize with the user_posts permission. Just because it is public, does not mean you can get the data - that would only work for Pages.

Facebook Graph API post comment fails

I'm using the FB graph API to post comments on different posts, but it does not work every time. There are posts that are okay to be "commented" and others fail every time. I'm using a Facebook user auth token (not a group or app token) to post comments.
The error returned is (#200) Permissions error.
At first I thought the post is not public and my user don't have a permission to comment on it, but when I go to it via web browser and logged in as the same user - he can manualy post comments on it. So via web it is working and via API it produces permissions error #200.
And just to mention again - I'm able to comment on certain posts with no issues.
Here is sample of my code that I think it is a fairly standard:
$oFacebook = new Facebook($config);
try {
$oFacebook->api('/'.$iEventId.'/comments', 'POST', array(
'message' => $sComment,
'access_token' => $sAccessToken
));
} catch (Exception $e){
print_r($e->getMessage());
}
$sComment is small plain text.
$sAccessToken is saved in DB access token. When I test it in the FB debug tools it says the token has publish_stream scope which is needed to post comments.
The same situation can be reproduced via Graph API explorer, so I assume it is not code-related issue.
In terms of reproducibility, here is one post ID that CAN'T be commented via API: 381578255242674. You can generate random access token in the explorer and try to POST to /381578255242674/comments.
And here is one post ID that CAN be commented: 265070490272041.
Any suggestions?

Posting on user wall doesn't work if link is included

I am trying to post to a user wall using the Graph API. I tested using my own wall, and I have authenticated my Facebook app to publish_stream.
post_params = {
access_token:FACEBOOK_APP_TOKEN,
link:'http://example.com',
picture:"http://example.com/images/logo.png",
message:"dummy",
description:'dummy'
}
get_facebook_client().client.post("#{user_fb_id}/feed", post_params)
I can successfully post something to my wall if I don't have the link parameter (containing our company url). If I include the link param, Facebook would still return the ID of the status update like {"id": "4804827_871793267189"}, like a successful post request, but post won't appear on my wall.
The above use the ruby gem rest-more, but this behavior happens when I hand code everything too.
I realize that I can post any other link (even other subdomain my company url).
So I think Facebook will ignore posting with a link which the user have shared before.
umm from looking at your code, if you add a comma at the end of link, wouldn't that fix the issue ?

How to edit an existing event using the Facebook Graph API

I've done extensive research on this, and am baffled. Similar questions on stackoverflow have been answered with, in in short: RTFM. Well, I've done that, and more, and I still can't find how to do this.
On the main FB Graph API page, documentation is given for authenticating, reading, publishing (creating), deleting Graph objects, but I don't see modifying anywhere.
The FB Graph API > User page gives description only of how to create and delete an event on behalf of an authenticated user. I've had no problem with these two actions.
The FB Graph API > Event tells you how to retrieve an existing event, as well as publish to the existing event, posts, links, feed, etc. Once again, no help with modifying.
I've tried (desperately) (':'s removed intentionally due to hyperlink limit):
Sending the same POST request as creating event, ie to https//graph.facebook.com/<user_id>/events, but with an extra 'id' parameter--the existing facebook event id. Facebook doesn't like that, gives me an 'id parameter already sent' error (I'm assuming the user's id).
POSTing to the event directly ie to https//graph.facebook.com/<fb_event_id>/ using the same auth_token as was used to create it. 'Post unsupported' error message.
The fields I send along with the POST are the same as those when creating the event-- 'name', 'location' etc.
If someone's been able to do this, one simple POST example would clear everything up for me.
Thanks!
UPDATE I started using the PHP SDK, but lack of examples disheartening. In hopes that this will save someone else frustration Here are doc examples augmented with an actual api call example:
"You can create an event for a user by issuing an HTTP POST request to
PROFILE_ID/events with the create_event permissions and the following
parameters."
$facebook->api('/'.$profile_id.'/events', 'POST', $params);
Normal enough ... but edit event docs (as of 12/7/12) are misleading:
"You can edit an event by issuing an HTTP POST to /EVENT_ID with the
create_event permission. "
$facebook->api('/events/'.$eventid, 'POST', $params);
Brian
I was able to update a page event by using a POST (not a PUT) directly to the event, using the account or page authentication token. It sounds exactly like what you did in 2 above.
curl -F 'access_token=...' \
-F 'name=A modified event name.' \
https://graph.facebook.com/event_id
I would suggest that you try just sending a modified name field. Also, because you have already created the event, you have the correct permissions. For those who don't know, you need the extended permissions of offline_access, create_event, manage_pages, etc.
It is frustrating, because at one time there was documentation on updates on the Facebook site, but now I can't find it.
Updating is the same as creating BUT, you can only update events created by your APP ID..

Retrieving albums from age-restricted (alcohol) pages results in "An unknown error occurred"

I've noticed when doing a Facebook Graph API call to retrieve a list of photo albums on an age-restricted page the following error occurs:
{error_code: 1, error_msg: "An unknown error occurred"}
I've tried both the JS API and the PHP API, same results.
For testing purposes, I am using an age-restricted page I created myself (permission set to Alcohol-related). I also have double checked that I am using a valid auth_token that has full permission to read and write photos to the page.
$albums = $facebook->api('/me/albums', 'GET', array(
'access_token' => 'XXX'
));
Please note the same code works fine on non-age restricted pages.
I should also mention, if I grab an album_id manually from Facebook, I have no problems posting photos to that album. The problem only seems to be with listing the albums.
Is this a bug on Facebook's side, or is there an extra step one must take for age-restriced pages?
Since the page is age restricted the user viewing this album should pass the age restriction check. Verify that the user viewing this passes that restriction.