我正在尝试获取PHP中的Robinhood选项数据,这需要进行身份验证。我觉得我的解决方法使我喘不过气来,但是尝试了一天之后,我准备寻求帮助。
到目前为止,我已经能够登录到Robinhood并获取令牌,然后使用该令牌成功验证第二个(oauth)令牌的请求。但是由于某些原因,我无法获得我选择的期权的期权数据(MSFT Put 75 Exp 1/17/2020,通过正确的身份验证https://api.robinhood.com/marketdata/options/0fd40096-9cbc-4b14-9df4-c1c9ea5f5729/在此处找到)
这是我的登录方式
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.robinhood.com/api-token-auth/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=example@gmail.com&password=mypassword");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
$result = json_decode($server_output);
$token = $result->token;
curl_close ($ch);
然后我将其转换为令牌
$url = 'https://api.robinhood.com/oauth2/migrate_token/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token '.$token));
$server_output = curl_exec ($ch);
$result = json_decode($server_output);
$oauth_token = $result->access_token;
curl_close ($ch);
到目前为止,到目前为止,效果很好,但是当我尝试以下操作时,我只会得到一个空白的答复:
$url = 'https://api.robinhood.com/marketdata/options/0fd40096-9cbc-4b14-9df4-c1c9ea5f5729/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$oauth_token));
$server_output = curl_exec ($ch);
var_dump($server_output);
curl_close ($ch);
对于我上半部遇到问题的任何帮助或想法,将不胜感激:)
编辑:回答WebCode.ie,结果print_r(curl_getinfo($ ch))为:
Array
(
[url] => https://api.robinhood.com/marketdata/options/0fd40096-
cbc-4b14-9df4-c1c9ea5f5729/
[content_type] => application/json
[http_code] => 405
[header_size] => 187
[request_size] => 453
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.386518
[namelookup_time] => 2.8E-5
[connect_time] => 0.094845
[pretransfer_time] => 0.289176
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => -1
[starttransfer_time] => 0.386491
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 52.200.3.207
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 84.x.x.x //my IP
[local_port] => 60974
)
答案 0 :(得分:1)
看起来我应该进行GET呼叫时正在进行POST呼叫。如果您遇到问题,请从我的最后一个代码块中删除此行。
curl_setopt($ch, CURLOPT_POST, 1);