未经验证的使用每日限额超过 [英] Daily Limit for Unauthenticated Use Exceeded

查看:120
本文介绍了未经验证的使用每日限额超过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Go中写一个简单的命令行google drive api。在我看来,到目前为止,我已经成功地验证了应用程序,因为我可以获取access_token和refresh_token。当我尝试使用令牌访问SDK Api时,出现问题,我收到以下错误消息:

  {
错误:{
错误:[
{
domain:usageLimits,
reason:dailyLimitExceededUnreg,
message :每日限制超出未经验证的使用,继续使用需要注册。,
extendedHelp:https://code.google.com/apis/console
}
],
code:403,
message:未经验证的使用的每日限制超出。继续使用需要注册。
}
}

我注意到的另一个奇怪的事是我没有看到我的google api控制台中的任何配额信息。所以不知道这是否是问题。但由于我可以被认证,所以我想我应该罚款控制台API设置。



下面是api查询的代码

  accessUrl:=https://www.googleapis.com/drive/v2/files+?access_token = \+ accessToken + \
if res,err:= http.Get(accessUrl); err == nil {
if b,err2:= ioutil.ReadAll(res.Body); err2 == nil {
fmt.Println(string(b))
} else {
fmt.Println(err2)
}
} else {
fmt.Println(err)
}


解决方案

发生在我身上的原因是:


  1. 我没有刷新令牌,我试图刷新。

  2. 我的令牌已过期,在这种情况下,我需要一个刷新令牌来获取新的访问令牌。

  3. 或者最后我有一个刷新令牌,但是我无意中过期它通过撤销访问,所以我可以在现场对测试网站进行测试。
  4. 所以首先检查以确保您的令牌没有过期,默认是3600秒或一小时,接下来如果你不确定是否可以随时刷新令牌。



    请记住棘手的事情是一旦一个应用程序被授权随后对服务器的请求将不会返回刷新令牌,我认为这种令牌很愚蠢,但是请注意这就是它的方式。因此,第一个认证可以得到一个刷新标记,而不是后续的请求。



    使用刷新标记获取新访问标记的代码如下所示:

      public static String refreshtoken(String refreshToken,SystemUser pUser)throws IOException {
    HttpParams httpParams = new BasicHttpParams();
    ClientConnectionManager connectionManager = new GAEConnectionManager();
    HttpClient client = new DefaultHttpClient(connectionManager,httpParams);
    HttpPost post = new HttpPost(https://accounts.google.com/o/oauth2/token);

    列表< NameValuePair> pairs = new ArrayList< NameValuePair>();
    pairs.add(new BasicNameValuePair(refresh_token,refreshToken));
    pairs.add(new BasicNameValuePair(client_id,YOUR_CLIENT_ID));
    pairs.add(new BasicNameValuePair(client_secret,YOUR_CLIENT_SECRET));
    pairs.add(new BasicNameValuePair(grant_type,refresh_token));

    post.setEntity(new UrlEncodedFormEntity(pairs));
    org.apache.http.HttpResponse lAuthExchangeResp = client.execute(post);
    字符串responseBody = EntityUtils.toString(lAuthExchangeResp.getEntity());
    ObjectMapper mapper = new ObjectMapper(); //可以重复使用,共享
    //全局
    Map< String,Object> userData = mapper.readValue(responseBody,Map.class);

    String access_token =(String)userData.get(access_token);
    String token_type =(String)userData.get(token_type);
    String id_token =(String)userData.get(token_type);
    String refresh_token =(String)userData.get(refresh_token);

    返回access_token;

    }

    我使用Google App Engine,因此必须使用GAEConnectionManager,您可以在这里获得这些详细信息: http: //peterkenji.blogspot.com/2009/08/using-apache-httpclient-4-with-google.html



    希望这有助于您!


    I am trying to write a simple command line google drive api in Go. It seem to me so far I have succeeded in authenticating the application as I can get access_token and the refresh_token. The problem happens when I try to access the SDK Api using the token, I get the below error message

    {
     "error": {
     "errors": [
     {
        "domain": "usageLimits",
        "reason": "dailyLimitExceededUnreg",
        "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
        "extendedHelp": "https://code.google.com/apis/console"
     }
    ],
     "code": 403,
     "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
     }
    }
    

    Another weird thing I noticed is that I do not see any quota information in my google api console. So not sure if that is the problem. But since I can be authenticated then I guess I should be fine in term of console api setup.

    Below is the code for the api query

     accessUrl := "https://www.googleapis.com/drive/v2/files" + "?access_token=\"" + accessToken + "\""
     if res , err := http.Get(accessUrl); err == nil {
          if b, err2 := ioutil.ReadAll(res.Body); err2 == nil {
                fmt.Println(string(b))
          }else{
              fmt.Println(err2)
          }   
     }else{
        fmt.Println(err)
     }  
    

    解决方案

    This happened to me because either:

    1. I didn't have a refresh token and I was trying to refresh.
    2. My token was expired, in which case I needed a refresh token to get a new access token.
    3. Or finally I had a refresh token, but I had inadvertently expired it by revoking access so I could test on the live site versus the test site.

    So first check to make sure your token's not expired, the default is 3600 seconds or one hour, next if you're unsure you can always refresh the token.

    And remember the tricky thing is once an app has been authorized subsequent requests to the server won't return a refresh token, which I think is kind of silly, but regardless that's the way it is. So the first auth you can get a refresh token, versus subsequent requests you can't.

    My code for getting a new access token using a refresh token looks like this:

    public static String refreshtoken(String refreshToken, SystemUser pUser) throws IOException {
        HttpParams httpParams = new BasicHttpParams();
        ClientConnectionManager connectionManager = new GAEConnectionManager();
        HttpClient client = new DefaultHttpClient(connectionManager, httpParams);
        HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
    
        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("refresh_token", refreshToken));
        pairs.add(new BasicNameValuePair("client_id", "YOUR_CLIENT_ID"));
        pairs.add(new BasicNameValuePair("client_secret", "YOUR_CLIENT_SECRET"));
        pairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
    
        post.setEntity(new UrlEncodedFormEntity(pairs));
        org.apache.http.HttpResponse lAuthExchangeResp = client.execute(post);
        String responseBody = EntityUtils.toString(lAuthExchangeResp.getEntity());
        ObjectMapper mapper = new ObjectMapper(); // can reuse, share
                                                    // globally
        Map<String, Object> userData = mapper.readValue(responseBody, Map.class);
    
        String access_token = (String) userData.get("access_token");
        String token_type = (String) userData.get("token_type");
        String id_token = (String) userData.get("token_type");
        String refresh_token = (String) userData.get("refresh_token");
    
        return access_token;
    
    }
    

    I am using Google App Engine and as a result have to use GAEConnectionManager, you get those details here: http://peterkenji.blogspot.com/2009/08/using-apache-httpclient-4-with-google.html.

    Hope this helps!

    这篇关于未经验证的使用每日限额超过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆