Facebook 0Auth客户端登录无法正常工作。 PHP APP

时间:2014-01-18 19:01:38

标签: php facebook-graph-api facebook-php-sdk

我使用PHP-SDK创建了一个facebook应用程序,该应用程序在用户的Feed上发布消息,它将在画布页面上打印应用程序访问令牌。它不会打开任何对话框以获取对应用程序的权限,同样在打开应用程序后它不会执行任何操作。它只显示“请登录”登录是一个按钮,有一些链接也没有工作。帮我!

<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('src/facebook.php');

$config = array(
'appId' => 'myappidhere',
'secret' => 'mysecrete,
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);

$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?> 
<html>
<head></head>
<body>

<?php
if($user_id) {

// We have a user ID, so probably a logged in user.
  // If not, we'll get an exception, which we handle below.
  try {
    $ret_obj = $facebook->api('/me/feed', 'POST',
                                array(
                                  'link' => 'www.facebook.com',
                                  'message' => 'Posting with the PHP SDK!Learning PHP     and Facebook API :D :D'
                             ));
    echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';

$token = $facebook->getAccessToken();
echo 'test';
echo $token;

 // Give the user a logout link 
    echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
  } catch(FacebookApiException $e) {
    // If the user is logged out, you can have a 
    // user ID even though the access token is invalid.
    // In this case, we'll get an exception, so we'll
    // just ask the user to login again here.
    $login_url = $facebook->getLoginUrl( array(
                   'scope' => 'publish_stream'
                   )); 
    echo 'Please <a href="' . $login_url . '">login.</a>';
    error_log($e->getType());
    error_log($e->getMessage());
  }   
} else {

  // No user, so print a link for the user to login
  // To post to a user's wall, we need publish_stream permission
  // We'll use the current URL as the redirect_uri, so we don't
  // need to specify it here.
  $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
  echo 'Please <a href="' . $login_url . '">login.</a>';

} 

&GT?;

     

我在Facebook的APP仪表板上有什么特殊设置吗?

1 个答案:

答案 0 :(得分:0)

您错过了单引号:

'secret' => 'mysecrete',

这只是在这篇文章中的拼写错误,而不是在你的代码中吗?是否显示任何错误?使用var_dump转储url:

$login_url = $facebook->getLoginUrl( array(
               'scope' => 'publish_stream'
               )); 
var_dump($login_url);