Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook - Publish Checkins using PHP SDK/JavaScript SDK
    text
    copied!<p>I'm trying to publish checkin using Facebook Graph API. I've gone through <a href="http://developers.facebook.com/docs/reference/api/user/" rel="nofollow">Facebook API documentation (checkins)</a> and also have the <code>publish_checkins</code> permission. However, my checkin is not getting published. May I know is there anything wrong or am I missing anything else? Thank you for your time :)</p> <p><strong>fbmain.php</strong></p> <pre><code>$user = $facebook-&gt;getUser(); $access_token = $facebook-&gt;getAccessToken(); // Session based API call if ($user) { try { $me = $facebook-&gt;api('/me'); if($me) { $_SESSION['fbID'] = $me['id']; $uid = $me['id']; } } catch (FacebookApiException $e) { error_log($e); } } else { echo "&lt;script type='text/javascript'&gt;top.location.href='$loginUrl';&lt;/script&gt;"; exit; } $loginUrl = $facebook-&gt;getLoginUrl( array( 'redirect_uri' =&gt; $redirect_url, 'scope' =&gt; status_update, publish_stream, publish_checkins, user_checkins, user_location, user_status' ) ); </code></pre> <p><strong>main.php - Using PHP SDK</strong> (Wrong SDK used in this example, should use JavaScript SDK instead)</p> <pre><code>&lt;?php include_once "fbmain.php"; if (!isset($_POST['latitude']) &amp;&amp; !isset($_POST['longitude'])) { ?&gt; &lt;html&gt; &lt;head&gt; //ajax POST of latitude and longitude &lt;/head&gt; &lt;body&gt; &lt;input type="button" value="Check In!" onclick="checkin();"/&gt;&lt;/span&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php } else { ?&gt; &lt;script type="text/javascript"&gt; function checkin() { try { $tryCatch = $facebook-&gt;api('/'.$uid.'/checkins', 'POST', array( 'access_token' =&gt; $facebook-&gt;getAccessToken(), 'place' =&gt; '165122993538708', 'message' =&gt;'MESSAGE_HERE', 'coordinates' =&gt; json_encode(array( 'latitude' =&gt; '1.3019399200902', 'longitude' =&gt; '103.84067653695' )) )); } catch(FacebookApiException $e) { $tryCatch=$e-&gt;getMessage(); } return $tryCatch; } &lt;/script&gt; &lt;?php } ?&gt; </code></pre> <p><strong>Question solved - Things to take note when publishing checkin</strong></p> <ul> <li>Make sure <code>publish_checkins</code> permission is granted.</li> <li>Must use <code>json_encode()</code> to encode <code>coordinates</code> parameter for PHP SDK.</li> <li><code>place</code> and <code>coordinates</code> parameters are compulsory.</li> <li>A re-authentication is required if you have just added <code>publish_checkins</code> permission to your existing list of allowed permissions.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload