Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the sample code from Yahoo Social SDK for PHP always returns NULL for the session variable?

Tags:

php

sdk

yahoo-api

I am trying to get the sample code from the Yahoo Social SDK for PHP page to work, With no luck.

This is the code snippet from the site:

<?php  
  require("Yahoo.inc");  

  // Your Consumer Key (API Key) goes here.  
  define('CONSUMER_KEY', "");  

  // Your Consumer Secret goes here.  
  define('CONSUMER_SECRET', "");  

  // Your application ID goes here.  
  define('APPID', "");  

  $session = YahooSession::requireSession(CONSUMER_KEY,CONSUMER_SECRET,APPID);  
?>  

I set the CONSUMER_KEY, CONSUMER_SECRET and APPID. But the $session variable is always NULL.

After digging around the yahoo.inc source code i traced the problem to this function:

function getRequestToken($consumerKey, $consumerSecret, $callback);

specifically this call in the function:

$response = $client->post($request_url, "application/x-www-form-urlencoded", $parameters);
$request_url: https://api.login.yahoo.com/oauth/v2/get_request_token
$parameters: has my callback url

And the $response variable is null !! which i think is the source of the problem. I am using the sample codes as it is. So, I'm not sure why this is happening.

Any ideas ?? What I am missing ?

like image 516
user1569804 Avatar asked Oct 18 '12 08:10

user1569804


1 Answers

try this:

$yahooUserData = YahooSession::requireSession($yahooConsumerKey, $yahooConsumerSecret, $yahooAppId, $returnUrl);

if (!empty($yahooUserData)) {
  $yahooUserId = $yahooUserData->guid;
  $accessToken = $yahooUserData->accessToken->key;
}
like image 101
THE AMAZING Avatar answered Sep 30 '22 06:09

THE AMAZING