mcfmullen Posted December 28, 2010 Share Posted December 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/ Share on other sites More sharing options...
BlueSkyIS Posted December 28, 2010 Share Posted December 28, 2010 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'];?> Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152212 Share on other sites More sharing options...
the182guy Posted December 28, 2010 Share Posted December 28, 2010 Just search for a cURL post example, very simple... Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152215 Share on other sites More sharing options...
mcfmullen Posted December 28, 2010 Author Share Posted December 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152260 Share on other sites More sharing options...
mcfmullen Posted December 28, 2010 Author Share Posted December 28, 2010 Just search for a cURL post example, very simple... The examples I find look nothing like this code. Could you elaborate? Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152261 Share on other sites More sharing options...
the182guy Posted December 28, 2010 Share Posted December 28, 2010 Perfect example here: http://davidwalsh.name/execute-http-post-php-curl Just change the form fields to the ones in your working form (message, token). Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152280 Share on other sites More sharing options...
mcfmullen Posted December 28, 2010 Author Share Posted December 28, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152287 Share on other sites More sharing options...
mcfmullen Posted December 28, 2010 Author Share Posted December 28, 2010 One thing though: How do I stop the code from printing my facebook ID#? Ex: it returns: {"id":"87658973_089756465457845"} Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152294 Share on other sites More sharing options...
the182guy Posted December 28, 2010 Share Posted December 28, 2010 You must be printing/echoing the $result variable somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152307 Share on other sites More sharing options...
mcfmullen Posted December 28, 2010 Author Share Posted December 28, 2010 Not at all, the complete page code is above, I haven't removed a thing. Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152358 Share on other sites More sharing options...
the182guy Posted December 29, 2010 Share Posted December 29, 2010 Try adding this option to the other cURL options curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152480 Share on other sites More sharing options...
mcfmullen Posted December 29, 2010 Author Share Posted December 29, 2010 That did the trick! Quote Link to comment https://forums.phpfreaks.com/topic/222830-facebook-curl-code/#findComment-1152659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.