[英]How to make API request using PHP cURL?
My request requires a token to make API requests. 我的请求需要令牌才能发出API请求。 Here is the cURL code they provide as example:
这是他们提供的cURL代码作为示例:
curl -v -L https://api.artsy.net/api/artists/andy-warhol -H 'X-Xapp-Token:myToken'
My code: 我的代码:
$postdata = array();
$postdata['client_id'] = 'myId';
$postdata['client_secret'] = 'myClient';
$postdata['xapp_token'] = 'myToken';
$cc = curl_init();
curl_setopt($cc,CURLOPT_POST,1);
curl_setopt($cc,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cc,CURLOPT_URL,"https://api.artsy.net/api/artists/andy-warhol");
curl_setopt($cc,CURLOPT_POSTFIELDS,$postdata);
$result = curl_exec($cc);
echo $result;
This should result in a JSON object that looks like: 这将导致一个JSON对象,如下所示:
{
"id": "4d8b92b34eb68a1b2c0003f4",
"slug": "andy-warhol",
"created_at": "2010-08-23T14:15:30+00:00",
"updated_at": "2017-08-25T17:25:51+00:00",
"name": "Andy Warhol",
"sortable_name": "Warhol Andy",
"gender": "male",
"birthday": "1928",
"hometown": "Pittsburgh, Pennsylvania",
"location": "New York, New York",
"nationality": "American",
//...
However it results in this result: 但是,结果如下:
{:type=>"other_error", :message=>"405 Not Allowed", "X-Frame-Options"=>"DENY", "X-Robots-Tag"=>"noindex", "Allow"=>"OPTIONS, GET, HEAD"}
I'm not too familiar with cURL so I've hit a wall with trying to translate the example code they provide. 我对cURL不太熟悉,因此在尝试翻译它们提供的示例代码时遇到了麻烦。 Any help would be deeply appreciated!
任何帮助将不胜感激!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.