0

我正在尝试访问 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

4

2 回答 2

1

对于那些在 2013 年 11 月 21 日发现此 VIA google 的人,此代码不再有效。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;
?>
于 2014-02-04T16:02:23.370 回答
0

您发布的代码有效(我自己测试过)。它返回(对于新创建的帐户):{"page_index": 0, "code": 200, "account_list": [], "prev_page": null, "page_num": 1, "next_page": null} 请记住,$whmusername 是您的 AppAnnie 电子邮件地址,而不是用户名。

于 2013-05-15T21:50:41.863 回答