gpt4 book ai didi

php - Facebook 图形 API + PHP SDK : get the URL of the large user picture

转载 作者:可可西里 更新时间:2023-10-31 23:55:12 25 4
gpt4 key购买 nike

我正在尝试将一个 Facebook 应用程序(一个嵌入 a small multiplayer Flash game 的 PHP 脚本)从旧的 FBML 重写为新的 iFrame 类型并且它有点工作:

<?php

require_once('facebook.php');

define('FB_API_ID', '182820975103876');
define('FB_AUTH_SECRET', 'XXX');

$facebook = new Facebook(array(
'appId' => FB_API_ID,
'secret' => FB_AUTH_SECRET,
'cookie' => true,
));

if (! $facebook->getSession()) {
printf('<script type="text/javascript">top.location.href="%s";</script>',
$facebook->getLoginUrl(
array('canvas' => 1,
'fbconnect' => 0,
#'req_perms' => 'user_location',
)));

} else {
try {
$me = $facebook->api('/me');

$first_name = $me['first_name'];
$city = $me['location']['name'];
$female = ($me['gender'] != 'male');
$fields = $facebook->api('/me', array(
'fields' => 'picture',
'type' => 'large'
));
$avatar = $fields['picture'];

# then I print swf tag and pass first_name;city;avatar to it

} catch (FacebookApiException $e) {
print('Error: ' . $e);
}
}

?>

但我认为获取用户个人资料图片的调用会导致我的脚本执行第二次 CURL 提取,这可能是可以避免的?而且我还想使用新的 GRAPH API 而不是旧的 REST API - 但我不确定如何重写该调用(我需要获取 largedirect 用户图片)。

最佳答案

如果您知道用户 ID,只需使用:

<img src="http://graph.facebook.com/<UID>/picture?type=large" />

另请注意,您可以使用该 URL 通过 cURL 检索内容。有需要的也可以use cURL to follow the redirects and get the final URL .

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,
"http://graph.facebook.com/<UID>/picture?type=large");

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

curl_close($ch);

var_dump($url);

关于php - Facebook 图形 API + PHP SDK : get the URL of the large user picture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5913973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com