【问题标题】:how to supply a google access token in order to retrieve user spreadsheet list?如何提供谷歌访问令牌以检索用户电子表格列表?
【发布时间】:2016-03-09 06:30:01
【问题描述】:

用户已成功授权我的应用使用他的数据。所以基本上我的应用程序有用户的访问令牌。现在我需要获取用户的电子表格列表。 有一个例子:

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    // Iterate through all of the spreadsheets returned
    for (SpreadsheetEntry spreadsheet : spreadsheets) {
      // Print the title of this spreadsheet to the screen
      System.out.println(spreadsheet.getTitle().getPlainText());
    }
  }
}

如何提供访问令牌?

【问题讨论】:

    标签: google-api google-sheets


    【解决方案1】:

    我添加了这个sn-p

    service.setOAuth2Credentials(new Credential(BearerToken
                .authorizationHeaderAccessMethod())
                .setFromTokenResponse(new TokenResponse().setAccessToken(accessToken)));
    

    和请求范围

    https://spreadsheets.google.com/feeds
    

    【讨论】:

    • 请提供完整的例子,如何获取accessToken?
    猜你喜欢
    • 2014-01-30
    • 2017-09-15
    • 2012-08-10
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多