Error when including redirect_uri with getLoginUrl (Facebook PHP SDK)

丶灬走出姿态 提交于 2020-01-05 15:06:33

问题


I want the user to be redirected to a particular webpage after logging in using Facebook. I created a LoginUrl using Facebook PHP SDK and the user clicks on this link to log in. I followed http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ when using the $facebook->getLoginUrl()

Problem: If I were to include the redirect_uri parameter, Facebook gives me an error An error occurred. Please try again later. The login url works fine without including the redirect_uri.

Anyone knows how to fix this? Thanks!

Non-working PHP Code

$loginUrl = $facebook->getLoginUrl(array(
        "scope" => "email,user_education_history,user_work_history",
        "redirect_uri" => "http://mydomain.com/login/facebook"
    ));

Working PHP Code

$loginUrl = $facebook->getLoginUrl(array(
        "scope" => "email,user_education_history,user_work_history",
    ));

回答1:


I had this same exact problem. FB changed the parameter from redirect_url to next from v2 to v3, and is poooooorly documented. Try next, should work for you.




回答2:


It's pretty old topic, but here is the solution I've found working, if someone reads it later... First thing is that you have missed the comma after "redirect_uri" in your "Non-working PHP Code". And if you have "App on Facebook" selected in your application settings (app in Canvas) then your redirect_uri must be the same as the url you have set for Canvas App. If you are using just Page Tab, the redirect_uri can be anything.

$loginUrl = $facebook->getLoginUrl(array(
    "scope" => "email,user_education_history,user_work_history",
    "redirect_uri" => "http://mydomain.com/login/facebook",
));


来源:https://stackoverflow.com/questions/9332666/error-when-including-redirect-uri-with-getloginurl-facebook-php-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!