使用 API 计算问题:"Not allowed access"

Chargify Problems Using API: "Not allowed access"

我正在尝试从我的 Chargify 测试帐户中检索信息,但我收到两个错误:401(在 "authenticating" 后消失)然后我收到 404,我不明白,因为它在我的浏览器上有效认证后

我不太擅长网络编码,所以我确定这就是问题所在。我用来尝试从 URL 获取数据的是这样的:

 $.ajax({
        type: "GET",
        url: "https://testingtests.chargify.com/customers.json",
        dataType: "json",
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', make_base_auth("someusername", "somepassword"));
        },
        success: function (response) {
            alert(response.d);
        },
        failure: function (response) {
            alert(response.d);
        },
    })

    function make_base_auth(user, password) {
        var tok = user + ':' + password;
        var hash = btoa(tok);
        return 'Basic ' + hash;
    }

编辑:我刚刚读到问题似乎是不能进行跨域访问,我必须使用 cURL 但我还没有找到任何关于如何使用它的信息。

Chargify 目前不支持 CORS(不能直接跨域访问),所以如果你想访问 API(通过代理)通过 JavaScript.

代理将是您使用 cURL(或任何现有 API 包装库)的地方,然后为您的客户端代码提供一个接口以使其工作。