开发者

Facebook.com error with getLoginUrl()

I generate a login u开发者_StackOverflowrl using:

$facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, "display"=>"page", 'next' => APP_URL, 'req_perms' => 'email,publish_stream,offline_access'))

However, when user clicks the link he is redirected to the page with a Facebook logo and a message 'Go to Facebook.com' underneath it. Why is this happening and how to fix it?

A live example: http://apps.facebook.com/soundofcamden/ (just click the authenticate link)


$login_url  = $facebook->getLoginUrl(array('canvas' => 1,'fbconnect' => 0, 'req_perms' => 'email,publish_stream,offline_access', 'next' => APP_URL));
echo '<div class="notice">You need to <a href="' . $login_url . '" onclick="top.location.href = \'' . $login_url . '\';">authenticate first</a>.</div>';

The solution.


I was encountering this issue, but it had a different cause. I'm adding it as an answer just incase it can help anyone that lands here.

Along with the facebook 'An error occurred. Please try later' error page, I was seeing the following PHP notices where I had implemented the facebook API:

  • Use of undefined constant ‘appId’ - assumed '‘appId’'
  • Use of undefined constant ‘secret’ - assumed '‘secret’'
  • Undefined index: appId
  • Undefined index: secret
  • Use of undefined constant scope - assumed 'scope'
  • Use of undefined constant redirect_uri - assumed 'redirect_uri'

The short answer is that the errors were caused by me copy/pasting code from the Facebook SDK Documentation.

The long answer is that the first four notices were caused by the quotes around array key names. They are unicode, which PHP wasn't recognising. Replacing them with standard single quotes fixed it.

The last two were caused by the array keys not being in quotes (as copied from the facebook SDK docs):

$params = array(
  scope => 'read_stream, friends_likes','email',
  redirect_uri => "CALLBACK-URL.COM"
);

Changed to:

$params = array(
  'scope' => 'read_stream, friends_likes','email',
  'redirect_uri' => "CALLBACK-URL.COM"
);

A few really simple problems that were a pain to spot! I hope this helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜