问题
I am using following code to send request from application to user. Everything was fine, but suddenly it stops to work and I get an error: OAuthException: (#2) Failed to create any app request
$config = array();
$config['appId'] = $this->app_id;
$config['secret'] = $this->app_secret;
$facebook = new Facebook($config);
$url = "https://graph.facebook.com/oauth/access_token?client_id={$this->app_id}&client_secret={$this->app_secret}&grant_type=client_credentials";
$token = file_get_contents($url);
$request = $facebook->api('/'.$id.'/apprequests', 'POST', array(
'message' => $text,
'access_token' => $token
)
);
Looks like token is valid, and I don't know where else can be the problem.
回答1:
The endpoint does not return the token only, but a string in the form access_token=YOUR_APP_ACCESS_TOKEN
.
So what you are passing as access_token
parameter is not really an access token – you’ll have to trim the access_token=
first.
回答2:
You need a valid app access_token to make the request to the API. The easiest way to create an app access_token is to use the app_id and secret. As the Facebook documentation states:
There is another method to make calls to the Graph API that doesn't require using a generated app token. You can just pass your app id and app secret as the access_token parameter when you make a call:
https://graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret
来源:https://stackoverflow.com/questions/15405293/oauthexception-2-failed-to-create-any-app-request