为什么来自Yahoo Social SDK for PHP的示例代码总是为会话变量返回NULL?

时间:2012-10-18 08:46:13

标签: php api sdk yahoo social

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

这是网站的代码段:

<?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);  
?>  

我设置了CONSUMER_KEYCONSUMER_SECRETAPPID$session variable始终为NULL。

在挖掘yahoo.inc源代码后,我将问题追溯到这个函数:

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

特别是在函数中的这个调用:

$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

$response变量是null !!我认为这是问题的根源。 我按原样使用示例代码。所以,我不确定为什么会这样。

任何想法?我缺少什么?

2 个答案:

答案 0 :(得分:1)

试试这个:

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

if (!empty($yahooUserData)) {
  $yahooUserId = $yahooUserData->guid;
  $accessToken = $yahooUserData->accessToken->key;
}

答案 1 :(得分:0)

指定返回网址并尝试此操作...

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

if (!empty($yahooUserData)) {
  $yahooUserId = $yahooUserData->guid;
  $accessToken = $yahooUserData->accessToken->key;
}