Php JSON POST请求-Pocket API/OAuth2.0

Php JSON POST请求-Pocket API/OAuth2.0,php,jquery,json,oauth,pocket,Php,Jquery,Json,Oauth,Pocket,我正在尝试使用PHP和JQuery构建一个与Pocket交互的应用程序 按照这里的步骤,我被困在“步骤2:获取请求令牌”上 文档告诉我: POST /v3/oauth/request HTTP/1.1 Host: getpocket.com Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Accept: application/x-www-form-urlencoded consumer_key=1234-abc

我正在尝试使用PHP和JQuery构建一个与Pocket交互的应用程序

按照这里的步骤,我被困在“步骤2:获取请求令牌”上

文档告诉我:

POST /v3/oauth/request HTTP/1.1
Host: getpocket.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Accept: application/x-www-form-urlencoded

consumer_key=1234-abcd1234abcd1234abcd1234&
redirect_uri=pocketapp1234:authorizationFinished
这对我来说毫无意义。如何格式化此OAuth JSON POST请求以使用PHP和/或JQuery

注意,我曾尝试使用,但它在回调时失败,并且似乎在文档明确说明POST时使用GET。我也想自己解决这个问题,这样我就可以学习如何将OAuth用于其他API

谢谢。

这似乎行得通:

<?php
session_start();
$redirect_uri = 'http://path/to/app/callback';
$url = 'https://getpocket.com/v3/oauth/request';
$data = array('consumer_key' => '*****', 'redirect_uri' => $redirect_uri);

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded; charset=UTF-8",
        'method'  => 'POST',
        'content' => http_build_query($data),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

$request_token = str_replace('code=','',$result);

$_SESSION['request_token'] = $request_token;

header("Location: https://getpocket.com/auth/authorize?request_token=$request_token&redirect_uri=$redirect_uri");
die();

?>

之后,我在会话中使用request_令牌以类似的方式获取访问令牌