简体   繁体   中英

Passing an OAuth token to the Yahoo API

I have created a new app using the Yahoo API. How can I pass the required headers using CURL functionality? I got this error message when I tried:

<yahoo:error xml:lang="en-US"><yahoo:description>Please provide valid credentials. OAuth oauth_problem="unable_to_determine_oauth_type", realm="yahooapis.com"</yahoo:description></yahoo:error>

How can I pass the required headers in this code:

$url ="http://fantasysports.yahooapis.com/fantasy/v2/team/223.l.431.t.1";  
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_URL, $url);   
//get the url contents  
$data = curl_exec($ch);     
//execute curl request curl_close($ch);   
$xml = simplexml_load_string($data);    
print_r($xml);    
exit;        

Once you'd obtained an OAuth 2.0 access token, use it in the following code:

$token = "<token>";

$url = "https://fantasysports.yahooapis.com/fantasy/v2/team/223.l.431.t.1?format=json";

$headers = array(
  'Authorization: Bearer ' . $token,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
print_r($json);

Notice that it presents the token in an Authorization HTTP header over a secure transport channel using the https URL scheme and requests to return the content as JSON using the format URL query parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM