略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: OAuth::getRequestToken

2024-05-03

OAuth::getRequestToken

(PECL OAuth >= 0.99.1)

OAuth::getRequestToken获取一个请求令牌

说明

public OAuth::getRequestToken(string $request_token_url, string $callback_url = ?): array

从服务提供者那里获取一个请求令牌、secret 、以及一些附带的响应参数。

参数

request_token_url

请求令牌 API 的 URL。

callback_url

OAuth 回调 URL。 如果传递了 callback_url 且为空值,则将其设置为“oob”即到 OAuth 2009.1 咨询的地址。

返回值

成功则返回一个包含解析过了的 OAuth 响应的数组,失败则返回 false

更新日志

版本 说明
1.0.0 以前失败时返回 null,而不是 false
0.99.9 增加 callback_url 参数。

范例

示例 #1 OAuth::getRequestToken() 例子

<?php
try {
    
$oauth = new OAuth(OAUTH_CONSUMER_KEY,OAUTH_CONSUMER_SECRET);
    
$request_token_info $oauth->getRequestToken("https://example.com/oauth/request_token");
    if(!empty(
$request_token_info)) {
        
print_r($request_token_info);
    } else {
        print 
"Failed fetching request token, response was: " $oauth->getLastResponse();
    }
} catch(
OAuthException $E) {
    echo 
"Response: "$E->lastResponse "\n";
}
?>

以上例程的输出类似于:

Array
(
    [oauth_token] => some_token
    [oauth_token_secret] => some_token_secret
)

参见

add a noteadd a note

User Contributed Notes 1 note

up
0
bohwaz
12 years ago
Please note that if you don't supply callback_url, the oauth parameter oauth_callback will not be sent to the server and will result in an error from the server, as this parameter is REQUIRED in the OAuth spec.

官方地址:https://www.php.net/manual/en/oauth.getrequesttoken.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3