0

I want to create circle in Google plus from my android app, for this I'm working with Google plus domain APIs then for API authentications i am following these steps and configuring all things that describe here: https://developers.google.com/+/domains/quickstart/java

But when i'm going to create circle as given here https://developers.google.com/+/domains/circles/creating i'm getting 400 Bad request "error": "invalid_grant" then its seems its authonticating but not creating circle.

Can anybody help me ? Thanks to consider...

My Code is:

In My Activity

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        domainDelegation = new DomainDelegation(this);
        PlusDomains service = null;
            try {
                service = domainDelegation.authenticate();
                People people = service.people();
                domainDelegation.createCircle(service);
            } catch (GeneralSecurityException | IOException e) {
                e.printStackTrace();
            }      
 }

In My DomainDelegation Class

private static final String SERVICE_ACCOUNT_EMAIL =     "xxxxxxxxx@developer.gserviceaccount.com"; 
private static final String USER_EMAIL = "name@domainname.com";
private static final List<String> SCOPE = Arrays.asList(
        "https://www.googleapis.com/auth/plus.me",
        "https://www.googleapis.com/auth/plus.stream.read",
        "https://www.googleapis.com/auth/plus.profiles.read",
        "https://www.googleapis.com/auth/plus.stream.write",
        "https://www.googleapis.com/auth/plus.circles.read",
        "https://www.googleapis.com/auth/plus.circles.write");

public  PlusDomains authenticate() throws GeneralSecurityException,
        IOException {  
    System.out.println(String.format("Authenticate the domain for %s",
            USER_EMAIL));
    Log.i(TAG, "Authenticate the domain for " + USER_EMAIL);

    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    // Setting the sub field with USER_EMAIL allows you to make API calls
    // using the special keyword
    // 'me' in place of a user id for that user.
    GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes(SCOPE)
            .setServiceAccountUser(USER_EMAIL)
             // I'm accessing .p12 file from my sdcard 
            .setServiceAccountPrivateKeyFromP12File(
                    new File(getReceiveFilename()))         
                            .build(); 

    // Create and return the Plus service object
    PlusDomains service = new PlusDomains.Builder(httpTransport,
            jsonFactory, credential).setApplicationName("GooglePlusDomainAPI").build();
    return service;
}
public void createCircle(PlusDomains service) {
    Circle circle = new Circle();
    circle.setDisplayName("Tech support");
    Circle result;
    try {
        result = service.circles().insert("me", circle).execute();
        System.out.println("Created 'Tech support' circle with id: " + result.getId());
        Log.i(TAG, "circle with id: "+ result.getId());
    } catch (IOException e) {
        e.printStackTrace();
        Log.v(TAG, "IOException: "+ e.getMessage());
    }
}

Getting Exception

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.googleplusdomainapi.DomainDelegation.createCircle(DomainDelegation.java:144)
at com.example.googleplusdomainapi.MainActivity.doThis(MainActivity.java:95)
at com.example.googleplusdomainapi.MainActivity.access$0(MainActivity.java:57)
at com.example.googleplusdomainapi.MainActivity$1$1.doInBackground(MainActivity.java:43)
at com.example.googleplusdomainapi.MainActivity$1$1.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Deven
  • 3,078
  • 1
  • 32
  • 34
  • Post the complete error. Is it TokenResponseException? – KRR Feb 26 '15 at 19:10
  • Please check the complete error (i have edited). – Deven Feb 27 '15 at 06:01
  • These would be helpful for you : http://stackoverflow.com/questions/16001668/invalid-grant-when-accessing-google-api and http://stackoverflow.com/questions/14188239/unable-to-get-token-using-google-apis-google-oauth-java-client-1-12-0-beta-for – KRR Feb 27 '15 at 16:54
  • I synchronized system clock in my phone that only was remaining things after check the above references, but now I'm getting "IOException: 403 Forbidden { "code" : 403, "errors" : [ { "domain" : "global", "message" : "Forbidden", "reason" : "forbidden" } ], "message" : "Forbidden" }" What i'm doing wrong, can you help me? – Deven Mar 02 '15 at 13:39

0 Answers0