0

Android アプリから Google プラスにサークルを作成したいのですが、このために Google プラス ドメイン API を使用し、API 認証のために次の手順に従って、ここで説明するすべてのものを構成しています: https://developers.google.com //+/ドメイン/クイックスタート/Java

しかし、ここで指定されているようにサークルを作成しようとすると https://developers.google.com/+/domains/circles/creating 400 Bad request "error": "invalid_grant" が表示され、認証されているようですが、認証されていないようですサークル作成中。

誰でも私を助けることができますか?ご検討ありがとうございます...

私のコードは次のとおりです。

マイ アクティビティ内

  @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();
            }      
 }

My DomainDelegation クラス内

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());
    }
}

例外の取得

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)
4

0 に答える 0