Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error posting message with link to Facebook

We are trying to post from PHP to a Facebook, we are using HybridAuth but the question is not related to it. What works: -posting to user profile, works fine,including when using picture and link -posting to page works including image(but not with link) What does not work -posting to page when we set a link(the url is not the issue since it works posting it to user profile )

The error is a generic error, that is not helping at all,thank you Facebook developers for giving us the trouble of guessing what is wrong

{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}}

I also made a simple script using curl to test this without involving the HybridAuth code and I get same error

<?
$access_token = "xxxxxx";
$page_id="352300454896456";
$msg = "test message ".time();
$title = "test title";
$uri = "http://www.example.com";
$desc = "test description";
//$pic = "http://ploscariu.com/simion/programming/kudani/kudani.png";

$attachment = array(
    'access_token' => $access_token,
    'message' => $msg,
    'name' => $title,
    'link' => $uri,
    'description' => $desc//,
//'picture'=>$pic,
//'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$page_id.'/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
?>

My question is, what is special about this "link" parameter and page posting? do we need some undocumented permission ? or is just some graph API bug I am wondering if we need sme different token for posting links ,but usually permission issue get back a good error message

enter image description here

in the image is the debug tool results on the access_token I get from the HybridAuth call, I tested using a short access token I get using JS API and posting with that works, but short access token are not a solution

Is the information in the image, about the token that it never expires true? How can I get such a token using the http API and curl(no SDKs)

like image 362
simion314 Avatar asked Jun 05 '15 10:06

simion314


People also ask

Why is my Facebook post link not working?

You might not be seeing the Facebook link preview you want because the info has been cached by Facebook. (Facebook saves the info from URLs and pages that have already been shared, for better performance.) So you just may need to force Facebook to clear the cache.

Does Facebook punish posts with links?

Creating Posts With Outside Links in Every Post I explained to him that Facebook penalizes pages that link to outside pages, especially if those pages include a link on every single post.

Why do I keep getting link broken on Facebook?

Occasionally when Facebook visits a site to grab the preview, it fails to do so correctly. Facebook caches whatever info it can grab about the URL (temporarily stores the info in memory). The next time the link is shared, Facebook uses the cached info and an incomplete or broken preview is displayed.

How do I enable links in a Facebook post?

Click inside the text field marked "What's on Your Mind," which is located right above your Facebook wall. Type the status update that you want to include with the link. Type or paste the URL of the Web page that you want to share into the text field. Include the "http://" section of the URL.


1 Answers

I found the issue, it was the access_token, I know it makes no sense that it worked without the link parameter but with the link parameter did not worked, but this is the truth. So you need to make sure you get the page access_token, you get that from me/accounts or with your SDK. The conclusion is that the Facebook developers are doing a bad job, wrong error messages, and allowing to post with wrong token.

like image 137
simion314 Avatar answered Sep 28 '22 21:09

simion314