Php 从graph api检索信息的文件\u get\u内容的替代方案
我正在开发我的第一个facebook,现在已经完成了,在我的应用程序中,我使用了Php 从graph api检索信息的文件\u get\u内容的替代方案,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在开发我的第一个facebook,现在已经完成了,在我的应用程序中,我使用了文件获取内容函数从graph api检索内容: $userName = json_decode(file_get_contents('http://graph.facebook.com/' . $userId)) -> name; 但问题是,我现在使用的主机不允许使用file\u get\u contents函数 所以我想知道我还可以使用哪些其他方法来检索 除此之外还有来自graph api的信息吗 通过
文件获取内容
函数从graph api检索内容:
$userName = json_decode(file_get_contents('http://graph.facebook.com/' . $userId)) -> name;
但问题是,我现在使用的主机不允许使用file\u get\u contents
函数
- 所以我想知道我还可以使用哪些其他方法来检索 除此之外还有来自graph api的信息吗
- 通过谷歌搜索,我发现facebook的php sdk提供了不同的
它的替代品。Ive
include('src/facebook.php')代码>包含在 我的代码,但我不知道如何使用,或有一种方法,我可以吗 使用sdk来解决我的问题
谢谢。最好的解决方案是使用Facebook PHP SDK 代码类似于:
$app_id = "Your App ID/API Key goes here";
$app_secret = "Your App secret goes here";
$site_url = "Your Site URL goes here";
include_once "src/facebook.php";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
if($user){
try{
$user_profile = $facebook->api('/me');
}catch(FacebookApiException $e){
$user = NULL;
}
}
if($user){
$logoutUrl = $facebook->getLogoutUrl();
}else{
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'read_stream publish_stream email',
'redirect_uri' => $site_url,
));
}
您可以在上找到详细的教程,请尝试SDK。在这里,
fopen
、fsockopen
和CURL
Facebook开发者PHP SDK文档是一个很好的起点。。。