我正在尝试通过他们的数据API对YouTube进行身份验证,只需要知道如何将标题从他们的示例(下面)转换为PHP + CURL函数调用.令人困惑的部分是授权部分,它打破了与自己的一组名称和值对的名称/值配对.
这个文档很好,除了我不知道如何在标题中格式化他们需要的内容.
他们的例子:
POST /accounts/OAuthGetRequestToken HTTP/1.1
Host: https://www.google.com
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth
oauth_consumer_key="example.com",
oauth_signature_method="RSA-SHA1",
oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
oauth_timestamp="137131200",
oauth_nonce="4572616e48616d6d65724c61686176",
oauth_version="1.0"
scope=http://gdata.youtube.com
Run Code Online (Sandbox Code Playgroud)
这不需要花哨,我只需要为一个帐户进行密钥交换,这样我就可以自动上传视频.我只是不知道如何将Authorization项目格式化为我的头文件数组
curl_setopt($ch, CURLOPT_HEADER, $headers);
Run Code Online (Sandbox Code Playgroud)
救命?
sha*_*oul 18
我之前没有使用过youtube api,但是我已经使用OAuth为Web应用程序创建了自己的REST api.
标题应该是:application/x-www-form-urlencoded并且如示例所示,参数为oauth_consumer_key,oauth_signature_method,oauth_signature等..需要使用post发送,所以你需要像这样:
$header[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode("oauth_consumer_key=example.com&
oauth_signature_method=RSA-SHA1&
oauth_signature=wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D&
oauth_timestamp=137131200&
oauth_nonce=4572616e48616d6d65724c61686176&
oauth_version=1.0"));
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助:D
问候.