java - invalid_grant error with Google Cloud Storage and Service Account -


i'm getting invalid_grant error when try access google cloud storage api service accounts. can't figure out what's wrong following code. idea ? it's first application using google storage api. appreciated.

source code

public static void main(string[] args) throws exception {     httptransport httptransport = new nethttptransport();     jsonfactory jsonfactory = new jacksonfactory();      list<string> scopes = new arraylist<string>();     scopes.add(storagescopes.devstorage_full_control);      credential credential = new googlecredential.builder()             .settransport(httptransport)             .setjsonfactory(jsonfactory)             .setserviceaccountid("xxxx")             .setserviceaccountprivatekeyfromp12file(new file("key.p12"))             .setserviceaccountscopes(scopes).build();      storage storage = new storage.builder(httptransport, jsonfactory,             credential).setapplicationname("test")             .build();      list<string> list = new arraylist<string>();     list<bucket> buckets = storage.buckets().list("xxxx").execute().getitems();     if(buckets != null) {         for(bucket b : buckets) {             list.add(b.getname());         }     } } 

error , stack trace

exception in thread "main" com.google.api.client.auth.oauth2.tokenresponseexception: 400 bad request {   "error" : "invalid_grant" }  @ com.google.api.client.auth.oauth2.tokenresponseexception.from(tokenresponseexception.java:105) @ com.google.api.client.auth.oauth2.tokenrequest.executeunparsed(tokenrequest.java:287) @ com.google.api.client.auth.oauth2.tokenrequest.execute(tokenrequest.java:307) @ com.google.api.client.googleapis.auth.oauth2.googlecredential.executerefreshtoken(googlecredential.java:269) @ com.google.api.client.auth.oauth2.credential.refreshtoken(credential.java:489) @ com.google.api.client.auth.oauth2.credential.intercept(credential.java:217) @ com.google.api.client.http.httprequest.execute(httprequest.java:858) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:410) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:343) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.execute(abstractgoogleclientrequest.java:460) @ googlestoragefetcher.main(googlestoragefetcher.java:143) 

this error due incorrect service account id. using client id (ending in .apps.googleusercontent.com) instead of email address (ending in @developer.gserviceaccount.com). there no problem email address.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -