0

google task apiを使用して、tasklist、update、delete、addなどを取得したいのですが、このリンクを見つけましたhttps://developers.google.com/google-apps/tasks/oauth-and-tasks-on-ステップバイステップの手順がそのリンクで与えられているアンドロイドでは、与えられているライブラリは非推奨です。

そのため、ここからlatetstライブラリgoogle-api-java-client-1.12.0-betaをダウンロードしましたhttp://code.google.com/p/google-api-java-client/downloads/detail?name=google- api-java-client-1.12.0-beta.zip&can = 2&q=およびgoogle -api-services-tasks-v1-rev5-java-1.12.0-betaはこちらhttp://code.google.com/p/ google-api-java-client / wiki / APIs#Tasks_APIと同様のコードを試してみてください。しかし、何も取得できません。アクセストークンを取得できますが、何も取得できません。最新のライブラリでは、ほとんどのメソッドが変更されているため、タスクを初期化し、TaskList、create、deleteなどを取得します......更新されたライブラリに関連して見つけたドキュメントは1つもありません。

よろしくお願いします。ありがとう。

4

1 に答える 1

0

このソリューションは、OAuth2.0を使用したサーバー間通信用です。これは3ステップのプロセスです。

  1. OAuth2.0を使用して認証する
  2. com.google.api.services.tasks.Tasksサービスオブジェクトを取得します
  3. 必要なタスクまたはタスクリストを取得する

このサンプルコードでは、ドメインID「abc.com」を使用し、ユーザーは「user1@abc.com」です。Gmailユーザーの場合は、Gmailid(abc@gmail.com)をconsumerkeyとして指定し、「xoauth_requestor_id」をgmailidのままにしてください。

import com.google.api.client.http.*;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.tasks.*;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;

public class GoogleConnection {
public Tasks setup() throws Exception {
    com.google.api.services.tasks.Tasks tasks = null;
    HttpRequestFactory httpRequestFactory = null;
    HttpRequestInitializer httpRequestInitializer = null;
    OAuthHmacSigner signer = new OAuthHmacSigner();
    HttpTransport httpTransport = new NetHttpTransport();
    OAuthParameters oauthParameters = new OAuthParameters();
    final ArrayMap<String, Object> customKeys = new ArrayMap<String, Object>();

    customKeys.add("xoauth_requestor_id", "user1@abc.com");
    signer.clientSharedSecret = "secret_key_received_from_google";
    oauthParameters.version = "2.0";
    oauthParameters.consumerKey = "abc.com";
    oauthParameters.signer = signer;
    httpRequestFactory = createRequestFactory(httpTransport, oauthParameters, "20000", "20000");
    httpRequestInitializer = httpRequestFactory.getInitializer();

    tasks = new  com.google.api.services.tasks.Tasks.Builder(httpTransport,  new JacksonFactory(), httpRequestInitializer)
            .setTasksRequestInitializer(new TasksRequestInitializer() {
              @Override
              public void initializeTasksRequest(TasksRequest<?> request) throws IOException  {
                @SuppressWarnings("rawtypes")
                TasksRequest tasksRequest =  (TasksRequest) request;
                tasksRequest.setUnknownKeys(customKeys);
                tasksRequest.setKey("keyapi_received_from_google_by_registering_your_app");
              }
            })
            .setApplicationName("")
            .build();

    return tasks;
  }
 }

タスクリストからタスクを取得するGoogleConnectionクラスをインスタンス化する

public List<com.google.api.services.tasks.model.Task> getTasksFromTaskList(String taskListId) throws Exception {
com.google.api.services.tasks.Tasks tasksService = googleConnection.setup();
com.google.api.services.tasks.model.Tasks result = tasksService .tasks().list(taskListId).execute();
return result.getItems();

}

于 2012-12-27T08:49:03.853 に答える