Jump to content

Facebook Curl Code?


mcfmullen

Recommended Posts

I'm trying to create a "Post" link that when clicked, will allow the user to post information onto their wall. I have figured out how to enable the proper permissions but the problem is one of two things:

 

My code:

<form method='post' action='https://graph.facebook.com/me/feed'>
<input type='text' name='message' id='message' />
<input type='text' name='access_token' id='access_token'
value='<?php echo $session['access_token'];?>' />
<input type='submit' />
</form>

 

The above DOES post onto my wall on behalf of my website, however, the browser attempts to download the url file for some reason and I get a popup saying "Cannot download file for whatever reason".

 

I've looked at Facebook's Open Graph API and found this:

curl -F 'access_token=...' \
     -F 'message=Check out this funny article' \
     -F 'link=http://www.example.com/article.html' \
     -F 'picture=http://www.example.com/article-thumbnail.jpg' \
     -F 'name=Article Title' \
     -F 'caption=Caption for the link' \
     -F 'description=Longer description of the link' \
     -F 'actions={"name": "View on Zombo", "link": "http://www.zombo.com"}' \
     -F 'privacy={"value": "ALL_FRIENDS"}' \
     -F 'targeting= {"countries":"US","regions":"6,53","locales":"6"}' \
     https://graph.facebook.com/me/feed

 

So my question is: How do I fix my current code to prevent the downloading of the url file OR how do I even use Facebook's code?

 

I've reseacrhed Curl and I don't understand how to translate the code into php (preferably) or javascript.

Link to comment
Share on other sites

if you mean to access a PHP session variable, this code is not correct:

 

<?php echo $session['access_token'];?>

 

it should be

 

<?php echo $_SESSION['access_token'];?>

 

It is not a session variable, but simply an array called session. The variable is called according to the Facebook PHP SDK.

Link to comment
Share on other sites

Solved!

 

	<?php		 
//extract data from the post
extract($_POST);

//set POST variables 
$url = 'https://graph.facebook.com/me/feed';
$fields = array(
	'access_token'=>urlencode($access_token),
	'message'=>urlencode($message),
	   );
    
//url-ify the data for the POST 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection 
$ch = curl_init();

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post 
$result = curl_exec($ch);

//close connection
curl_close($ch);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.