• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • OAuth::getRequestToken()

    (PECL OAuth >= 0.99.1)

    获取一个请求令牌

    说明

    publicOAuth::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参数。

    范例

    Example #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
    )
    

    参见

    • OAuth::getLastResponse() 获取最后一次的响应
    • OAuth::getLastResponseInfo() 获取关于最后一次响应的 HTTP 信息
    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.