Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api Adsense API获取“错误:需要登录”_Google Api_Google Oauth_Adsense Api - Fatal编程技术网

Google api Adsense API获取“错误:需要登录”

Google api Adsense API获取“错误:需要登录”,google-api,google-oauth,adsense-api,Google Api,Google Oauth,Adsense Api,我正在使用API浏览器工具为google adsense创建一些请求URL。以下是explorer工具生成的请求url,它提供了对今天收入的响应:https://www.googleapis.com/adsense/v1.4/reports?startDate=today&endDate=today&accountId=MY_ACCOUNT_ID&metric=EARNINGS&key=MY_API_KEY 但是,当我尝试在浏览器或代码中使用此url时,它会给出以下响应: { "error":

我正在使用API浏览器工具为google adsense创建一些请求URL。以下是explorer工具生成的请求url,它提供了对今天收入的响应:https://www.googleapis.com/adsense/v1.4/reports?startDate=today&endDate=today&accountId=MY_ACCOUNT_ID&metric=EARNINGS&key=MY_API_KEY

但是,当我尝试在浏览器或代码中使用此url时,它会给出以下响应:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}
我不确定我错过了什么,请使用此url。我已经在我的google开发者控制台上激活了adsense API。

您需要用您的API密钥替换我的API密钥,并以相同的方式替换我的帐户ID。

密钥参数是访问公共数据的公共API密钥

access_token参数用于访问私有用户数据

在您的情况下,您正在尝试访问您的私人帐户,并且应该使用访问令牌

要获得访问令牌,您需要使用Oauth2或服务帐户对应用程序进行身份验证。一旦您获得访问令牌并将其与您的请求一起发送,如下所示:


当然可以。我没有在这里展示这一点,原因很明显。我的代码实际上有这两个地方,然后你可能需要采取这与谷歌!祝你好运