简体   繁体   中英

Facebook PHP SDK works only on localhost

I have a mobile app which was interfacing with the PHP Facebook SDK fine until recently. Now it will only sign in when I have it pointed at my localhost development server. Frankly, I'm completely stumped. Of course I've checked the site url inside the Facebook developer center. Everything is pointed at the live server. Yet only the development server will sign in. Any suggestions?

These domains work:
http://localhost:8888
http://testsite2:8888

These domains will not work:
http://*.com
https://*.com

As requested, here is my facebook code:

$config = array();
$config['appId'] = Configure::read('FB_APP_ID');
$config['secret'] = Configure::read('FB_APP_SECRET');
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);      
$facebook->setAccessToken($this->data['User']['fbtoken']);
$receivedfbid = $facebook->getUser();

This works correctly on my development server and it used to work fine on the live server until recently. Just to reiterate, the facebook developer center is configured for "site url" to the live server. So that is not the problem.

在此处输入图片说明

I had the same issue with my web app on webhost but it worked fine on localhost.

In my case it was related to cURL and ssl.

A quick way to see if it is a SSL problem is to tell fb php sdk to accept any SSL cert, to do that, Add this to your base_facebook.php file:

$opts[CURLOPT_SSL_VERIFYPEER] = false; 
   curl_setopt_array($ch, $opts);

Place it right before $result = curl_exec($ch);

I know you said you tested on non SSL connections but your base_facebook.php file is still looking for a ssl cert.
For further reading see: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

更改您在developer.facebook.com中的应用程序设置,希望您配置为本地主机

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