Php 无法归档\u以使\u内容正常工作
我正在使用facebook graph api检索登录用户的信息Php 无法归档\u以使\u内容正常工作,php,json,facebook,facebook-graph-api,file-get-contents,Php,Json,Facebook,Facebook Graph Api,File Get Contents,我正在使用facebook graph api检索登录用户的信息 $facebookdata = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $fb_accesstoken . '&fields=name,picture'),true); 现在,当我var\u dump时,我得到空值。我确实尝试转到url。它显示名称和照片URL 非常感谢您的帮助。检查您的php.ini中是否
$facebookdata = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $fb_accesstoken . '&fields=name,picture'),true);
现在,当我var\u dump时,我得到空值。我确实尝试转到url。它显示名称和照片URL
非常感谢您的帮助。检查您的php.ini
中是否启用了。否则,请进行调整,因为此时无法从http URL读取文件内容
第二,提高你的水平。它应该告诉你的
如果没有收到错误消息,则可能会阻止使用PHPuser\u代理进行访问。还有另一个php.ini设置。或者,也可以试试看 检查您的php.ini
中是否启用了。否则,请进行调整,因为此时无法从http URL读取文件内容
第二,提高你的水平。它应该告诉你的
如果没有收到错误消息,则可能会阻止使用PHPuser\u代理进行访问。还有另一个php.ini设置。或者,也可以试试看 不使用文件获取内容
您可以使用更易于使用的Facebook PHP SDK():
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$facebook->setAccessToken("...");
$args['fields'] = "name,picture";
$facebookdata = $facebook->api('/me', $args);
如果您想查看获取用户访问令牌的流程,请查看(有详细记录的)
希望有帮助 不使用文件获取内容
您可以使用更易于使用的Facebook PHP SDK():
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$facebook->setAccessToken("...");
$args['fields'] = "name,picture";
$facebookdata = $facebook->api('/me', $args);
如果您想查看获取用户访问令牌的流程,请查看(有详细记录的)
希望有帮助 您应该确定请求返回的http响应代码
我发现file_get_contents()只有在http响应为200时才起作用
如果响应代码为404(未找到页面)、400(错误请求)等,则不会返回字符串
使用不正确的访问令牌点击Facebook API返回400
例如:
文件\u获取\u内容(),带有'http://www.google.co.uk谷歌的http响应是200
文件\u获取\u内容(),带有'http://www.google.co.uk/me'为空,来自google的http响应为404您应该确定请求返回的http响应代码
//i had the same problem before.for some reason the server has a problem with file_get_contents and i used this function.try it instead
/* gets the data from a URL */
function get_myurl_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'https://graph.facebook.com/me?access_token=' . $fb_accesstoken . '&fields=name,picture';
$facebookdata = json_decode(get_myurl_data($url));
我发现file_get_contents()只有在http响应为200时才起作用
如果响应代码为404(未找到页面)、400(错误请求)等,则不会返回字符串
使用不正确的访问令牌点击Facebook API返回400
例如:
文件\u获取\u内容(),带有'http://www.google.co.uk谷歌的http响应是200
文件\u获取\u内容(),带有'http://www.google.co.uk/me'为空,来自google的http响应为404首先尝试var\u dump
而不使用json\u解码
,然后查看输出。“调试”你的程序@我也试过了,它显示bool(false)。请帮忙,这意味着问题是它不工作。尝试获取其他页面(例如此页面)继续调试。首先尝试var\u dump
而不使用json\u解码
,然后查看输出。“调试”你的程序@我也试过了,它显示bool(false)。请帮忙,这意味着问题是它不工作。尝试获取其他页面(例如此页面)继续调试。我尝试将文件内容与其他URL一起使用,效果很好。已启用“允许url\U fopen”。谢谢你的帮助。还有https URL吗?您当前的错误级别是多少?$http\u response\u header
说了些什么?我尝试将file\u get\u内容与其他URL一起使用,效果很好。已启用“允许url\U fopen”。谢谢你的帮助。还有https URL吗?您当前的错误级别是多少?$http\u response\u header
说了什么?
//i had the same problem before.for some reason the server has a problem with file_get_contents and i used this function.try it instead
/* gets the data from a URL */
function get_myurl_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'https://graph.facebook.com/me?access_token=' . $fb_accesstoken . '&fields=name,picture';
$facebookdata = json_decode(get_myurl_data($url));