我正在尝试访问appannie.com的api。我似乎无法通过身份验证。这是我拥有的,有什么想法吗?
<?php
$whmusername = "username";
$whmpassword = "password";
$query = "https://api.appannie.com/v1/accounts";
$ch = curl_init();
// Sets the URL cURL will open
curl_setopt($ch, CURLOPT_URL, $query);
// Here's the HTTP auth
// The 3rd argument is your Twitter username and password joined with a colon
curl_setopt($ch, CURLOPT_USERPWD, $whmusername.":".$whmpassword);
// Makes curl_exec() return server response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// And here's the result XML
$response = curl_exec($ch);
curl_close($ch);
print $response;
?>
这是他们的api文档的链接: http://appannie.zendesk.com/categories/20082753-Analytics-API http://support.appannie.com/entries/23215057-2-Authentication
答案 0 :(得分:1)
对于那些发现此威盛谷歌的用户,此代码自2013年11月21日起不再有效.AppAnnie弃用了HTTP的基本身份验证。
您现在需要申请位于https://www.appannie.com/account/api/key/
的API密钥获得API密钥后,您可以使用以下代码在AppAnnie上验证自己:
<?php
$query = "https://api.appannie.com/v1/accounts";
$ch = curl_init();
// Sets the URL cURL will open
curl_setopt($ch, CURLOPT_URL, $query);
// Here's the HTTP auth
// The 3rd argument is your Twitter username and password joined with a colon
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: bearer API_KEY'));
// Makes curl_exec() return server response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// And here's the result XML
$response = curl_exec($ch);
curl_close($ch);
print $response;
?>
答案 1 :(得分:0)
您发布的代码有效(我自己测试)。它返回(对于新创建的帐户):{"page_index": 0, "code": 200, "account_list": [], "prev_page": null, "page_num": 1, "next_page": null}
请记住,$ whmusername是您的AppAnnie电子邮件地址,而不是用户名。