简体   繁体   中英

Invalid Credentials using Heroku URL as Canvas URL

I am using Heroku to make a php application on Facebook. I want to have the Heroku URL be the Canvas URL in my application. However, when I put the URL in the Basic page and then try to open my application by going to http://apps.facebook.com/status_related_test , the canvas displays "Invalid credentials" and redirects to the URL of the application, https://young-warrior-3712.herokuapp.com .

Any ideas what I might be doing wrong or how to fix this?

ETA:
When I go directly to the application link (https://young-warrior-3712.herokuapp.com), I can sign in successfully. It is only when I try to go to the Facebook App page that it doesn't work.

norabora, I got the solution for this in other post, after suffering long hours I finally made it! this is the link to the post I answered to: Answer to redirection in FB app canvas

Hope you'll find it useful... Good Luck!

Tried it myself, the index.php can't fetch $token on line 35 on page load.

$token = FBUtils::login(AppInfo::getHome());
if ($token) {
...
} else {
  // Stop running if we did not get a valid response from logging in
  exit("Invalid credentials");
}

Use the procedure from http://developers.facebook.com/docs/authentication/ to ascertain why FBUtils::login fails.

Alternatively, you may want to use Facebook PHP SDK (http://developers.facebook.com/docs/reference/php/) which already has functions like "Facebook::getLoginUrl" and bypass this error.

Go to the getHome() function in AppInfo.php and find the following line:

return ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?: "http") . "://" . $_SERVER['HTTP_HOST'] . "/"; 

You have to change $_SERVER['HTTP_HOST'] to your canvas page URL:

return ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?: "http") . "://" . "apps.facebook.com/yourappname"  . "/"; 

where yourappname should be your app namespace.

Note that if you apply these changes you won't be able to use the heroku page of your application because it will redirect to the canvas page.

I was experiencing a similar problem trying to include my app in a pages tab on Facebook. The answer to the problem is to edit FBUtils.php.

Find:

      echo("<script> window.location.href='" . $authorize_url . "'</script>");

Replace with:

echo("<script> window.location.href='" . $authorize_url . "'</script>");

This line can be found at line 94 of FBUtils.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM