6

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 ?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
user1569804
  • 83
  • 1
  • 7
  • can you check error_log file ? or enable error_reporting error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', true); – GBD Oct 18 '12 at 08:58
  • do session_start() at start of your php file or use this https://github.com/yahoo/yos-social-php/blob/master/sample/sampleapp.php – GBD Oct 18 '12 at 09:17
  • 2
    I checked the error logs, and there a mention of curl having a SSL problem. so I added this line to Yahoo.inc: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); now it's working...thanks :) – user1569804 Oct 18 '12 at 15:56

2 Answers2

1

try this:

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

if (!empty($yahooUserData)) {
  $yahooUserId = $yahooUserData->guid;
  $accessToken = $yahooUserData->accessToken->key;
}
THE AMAZING
  • 1,496
  • 2
  • 16
  • 38
0

Specify return url and Try this ...

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

if (!empty($yahooUserData)) {
  $yahooUserId = $yahooUserData->guid;
  $accessToken = $yahooUserData->accessToken->key;
}
Dino Babu
  • 5,814
  • 3
  • 24
  • 33