简体   繁体   English

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

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

I am trying to get the sample code from the Yahoo Social SDK for PHP page to work, With no luck.我正在尝试从 Yahoo Social SDK for PHP 页面获取示例代码,但没有成功。

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 .我设置了CONSUMER_KEYCONSUMER_SECRETAPPID But the $session variable is always NULL.$session variable始终为 NULL。

After digging around the yahoo.inc source code i traced the problem to this function:在挖掘了 yahoo.inc 源代码后,我将问题追溯到这个函数:

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 !!并且$response变量为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 ?我错过了什么?

try this:尝试这个:

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

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

Specify return url and Try this ...指定返回 url 并尝试这个...

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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