Facebook-使用PHP SDK/JavaScript SDK发布签到 [英] Facebook - Publish Checkins using PHP SDK/JavaScript SDK

查看:74
本文介绍了Facebook-使用PHP SDK/JavaScript SDK发布签到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Facebook Graph API发布签到.我已经阅读过 Facebook API文档(签入),并且还具有publish_checkins权限.但是,我的签到没有发布.我可以知道有什么问题吗,还是我想念其他东西吗?谢谢您的时间:)

I'm trying to publish checkin using Facebook Graph API. I've gone through Facebook API documentation (checkins) and also have the publish_checkins 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 :)

fbmain.php

$user = $facebook->getUser();
$access_token = $facebook->getAccessToken();

// Session based API call
if ($user) {
    try {
            $me = $facebook->api('/me');
            if($me)
            {
                $_SESSION['fbID'] = $me['id'];
                $uid = $me['id'];
            }
        } catch (FacebookApiException $e) {
          error_log($e);   
        }
}
else {
   echo "<script type='text/javascript'>top.location.href='$loginUrl';</script>";
   exit;
}

$loginUrl = $facebook->getLoginUrl(
        array(
            'redirect_uri' => $redirect_url,
            'scope' => status_update, publish_stream, publish_checkins, 
                user_checkins, user_location, user_status'
            )
);

main.php-使用PHP SDK (此示例中使用的SDK错误,应改为使用JavaScript SDK)

main.php - Using PHP SDK (Wrong SDK used in this example, should use JavaScript SDK instead)

<?php
    include_once "fbmain.php";

    if (!isset($_POST['latitude']) && !isset($_POST['longitude']))
    {
?>
<html>
    <head>
        //ajax POST of latitude and longitude
    </head>

    <body>
        <input type="button" value="Check In!" onclick="checkin();"/></span>
    </body>
</html>
<?php
}
else
{
?>
<script type="text/javascript">
    function checkin()
    {
        try
        {
            $tryCatch = $facebook->api('/'.$uid.'/checkins', 'POST', array(
                'access_token' => $facebook->getAccessToken(),
                'place' => '165122993538708',
                'message' =>'MESSAGE_HERE',
                'coordinates' => json_encode(array(
                    'latitude'  => '1.3019399200902',
                    'longitude' => '103.84067653695'
                ))
            ));
        }
        catch(FacebookApiException $e)
        {
            $tryCatch=$e->getMessage();
        }
        return $tryCatch;
    }
</script>
<?php
}
?>

问题已解决-发布签到时要注意的事项

  • 确保已授予publish_checkins权限.
  • 必须使用json_encode()来编码PHP SDK的coordinates参数.
  • placecoordinates参数是强制性的.
  • 如果您刚刚在现有的允许权限列表中添加了publish_checkins权限,则需要重新认证.
  • Make sure publish_checkins permission is granted.
  • Must use json_encode() to encode coordinates parameter for PHP SDK.
  • place and coordinates parameters are compulsory.
  • A re-authentication is required if you have just added publish_checkins permission to your existing list of allowed permissions.

推荐答案

显然,我在问题中发布的配置和PHP签入功能是正确的.但是,Nehal指出,对于我的情况,我应该使用JavaScript SDK而不是PHP SDK.供将来参考...

Apparently, the configuration and the PHP checkin function that I have posted in the question are correct. However, I should use JavaScript SDK instead of PHP SDK for my case as pointed out by Nehal. For future references...

使用JavaScript SDK

function checkin()
{
    FB.api('/me/checkins', 'post', 
    { message: 'MESSAGE_HERE',
       place: 165122993538708,
       coordinates: {
           'latitude': 1.3019399200902,
           'longitude': 103.84067653695
       }
    },
        function (response) {
            alert("Checked in!");
        }
    );
}

这篇关于Facebook-使用PHP SDK/JavaScript SDK发布签到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆