google api - Urlshortener and 403 error on Android App -


this first question on stackoverflow , brain burned out due post have read , tests made.

at app add short url's service of google. had read post, have generated api-key android application in google api console, put key in manifest, enable url shortener api , set quota per-user limit 50 (in moment i'm user of app on physical smartphone) method short url give me this:

com.google.api.client.googleapis.json.googlejsonresponseexception: 403 forbidden { "code": 403, "errors": [ { "domain": "usagelimits", "message": "daily limit unauthenticated use exceeded. continued use requires signup.", "reason": "dailylimitexceededunreg", "extendedhelp": "https://code.google.com/apis/console" } ], "message": "daily limit unauthenticated use exceeded. continued use requires signup." } 

this code of method

import android.os.asynctask; import android.util.log;  import com.google.api.client.extensions.android.http.androidhttp; import com.google.api.client.extensions.android.json.androidjsonfactory; import com.google.api.services.urlshortener.urlshortener; import com.google.api.services.urlshortener.model.url;  import java.io.ioexception; import java.util.concurrent.executionexception;  [...]  public string shorturl (string url) {     log.d(tag, "start shorturl url = " + url);     //*** gruppo asynctask ***//     asynctask <string, void, string> shorturlengine = new asynctask<string, void, string>() {         @override         protected void onpreexecute() {             log.d(tag, "preexecute");         }          @override         protected string doinbackground(string... params) {             log.d(tag, "start doinbackground");             log.d(tag, "params[0] = " + params[0]);             urlshortener.builder builder = new urlshortener.builder (androidhttp.newcompatibletransport(), androidjsonfactory.getdefaultinstance(), null);             builder.setapplicationname("it.kabadroid42.testurl");             urlshortener urlshortener = builder.build();              com.google.api.services.urlshortener.model.url url = new url();             url.setlongurl(params[0]);             try {                 url = urlshortener.url().insert(url).execute();                 log.d(tag, string.valueof(url.getid()));                 return url.getid();             } catch (ioexception e) {                 log.d(tag, string.valueof(e));                 return "error (1)";             }         }          @override         protected void onpostexecute(string s) {             log.d(tag, "postexecute");         }     };     //*** fine ***//     string urlout = "error (2)";     try {          urlout = shorturlengine.execute(url).get();     } catch (interruptedexception e) {         log.d(tag, "eccezione 1");         e.printstacktrace();     } catch (executionexception e) {         log.d(tag, "eccezione 2");         e.printstacktrace();     }      return urlout; } 

i noticed if put corret api-key or fake in manifest result same. think app dont send api-key dont have idea why. completeness part of androidmanifest.xml

<application ...>   ... <meta-data         android:name="com.google.android.urlshortener.api_key"         android:value="xxxx api key xxxx"/>   ... </application> 

i have tried move meta-data in various position, change api-key 403 error said me hello every time.

thank suggestion , sorry english, not native language tuesday start english course :)

was running same problem , solved addition of setkey() shown below. use android key api console, not web key may have used if using old shortener via web call.

    try {             url = urlshortener.url().insert(url).setkey({your api key}).execute();             log.d(tag, string.valueof(url.getid()));             return url.getid();         } catch (ioexception e) {             log.d(tag, string.valueof(e));             return "error (1)";         } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -