[英]Why is the sample code from Yahoo Social SDK for PHP always returns NULL for the session variable?
我正在嘗試從 Yahoo Social SDK for PHP 頁面獲取示例代碼,但沒有成功。
這是該網站的代碼片段:
<?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_KEY
、 CONSUMER_SECRET
和APPID
。 但$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
! 我認為這是問題的根源。 我正在使用示例代碼。 所以,我不確定為什么會這樣。
有任何想法嗎 ?? 我錯過了什么?
嘗試這個:
$yahooUserData = YahooSession::requireSession($yahooConsumerKey, $yahooConsumerSecret, $yahooAppId, $returnUrl);
if (!empty($yahooUserData)) {
$yahooUserId = $yahooUserData->guid;
$accessToken = $yahooUserData->accessToken->key;
}
指定返回 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.