2011-06-23 19 views
3

我正在通过我的开发人员测试帐户处理应用程序,我所做的所有工作都是试图向我的用户发布测试通知。我做这个使用Facebook要求2.0文档,所以我的代码如下所示:Facebook请求2.0错误#200参数ID中的所有用户都必须接受TOS

$token_url = "https://graph.facebook.com/oauth/access_token?" . 
       "client_id=" . $app_id . 
       "&client_secret=" . $app_secret . 
       "&grant_type=client_credentials"; 

       $app_access_token = file_get_contents($token_url); 


       $user_id = $this->user->id; 
       $apprequest_url ="https://graph.facebook.com/" . 
           $user_id . 
           "/apprequests?message='testing notification'" . 
           "&" . 
           $app_access_token . "&method=post"; 

       $result = file_get_contents($apprequest_url); 
       echo "Request id number: " . $result; 

当我这样做,我得到的是说在网页上的错误“未能打开流”,但是当我复制和将网址粘贴到地址栏中我不会收到任何错误并返回请求ID。任何人都知道为什么会发生这种情况?

回答

0

我解决它使用curl代替file_get_contents。由于某些原因,用于抛出错误的file_get_contents

的cpde的卷曲是:

$ch = curl_init(); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
     curl_setopt($ch, CURLOPT_URL, $apprequest_url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_HEADER, false); 

$result = curl_exec($ch); 
curl_close($ch); 

我知道我是一个痘痘晚了,但我希望它可以帮助别人。

相关问题