Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用android电子表格服务类的Google电子表格_Android_Google Sheets_Google Spreadsheet Api - Fatal编程技术网

使用android电子表格服务类的Google电子表格

使用android电子表格服务类的Google电子表格,android,google-sheets,google-spreadsheet-api,Android,Google Sheets,Google Spreadsheet Api,当尝试使用SpreadsheetService类访问Google电子表格时,我得到了异常InInitializeRerror 以下是我的代码: 我已将以下jar文件包括到该文件中 gdata-client-1.0.jar gdata-client-meta-1.0.jar gdata-core-1.0.jar gdata-spreadsheet-3.0.jar gdata-spreadsheet-meta-3.0.jar google-api-client-1.12.0-beta.jar goo

当尝试使用SpreadsheetService类访问Google电子表格时,我得到了
异常InInitializeRerror

以下是我的代码:

我已将以下jar文件包括到该文件中

gdata-client-1.0.jar
gdata-client-meta-1.0.jar
gdata-core-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.12.0-beta.jar
google-api-client-android-1.12.0-beta.jar
google-http-client-1.12.0-beta.jar
google-http-client-android-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
gson-2.1.jar
guava-13.0.1.jar

jackson-core-asl-1.9.9.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar
代码如下:

SpreadsheetService service = new SpreadsheetService("ContactsApp");// Exception occured here
service.setProtocolVersion(SpreadsheetService.Versions.V3);
try {
service.setUserCredentials("abcd@gmail.com","pwd1234");
    } catch (Exception e) {
e.printStackTrace();
}
ArrayList<ContactsModel> list = new ArrayList<ContactsModel>();
try {

String url=
 "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";

// turn the string into a URL
URL urlString = new URL(url);

// You could substitute a cell feed here in place of
// the list feed

ListFeed feed = service.getFeed(urlString, ListFeed.class);

for (ListEntry entry : feed.getEntries()) {
ContactsModel contact = new ContactsModel();
CustomElementCollection elements = entry.getCustomElements();
contact.EmpID = elements.getValue("Emp Id");
contact.Name = elements.getValue("Name");
contact.personalEmail = elements.getValue("personal email");
contact.workEmail = elements.getValue("work email");
contact.emergencyContact = elements.getValue("Emergency Contact");
contact.relation = elements.getValue("Relation");

list.add(contact);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
SpreadsheetService服务=新的电子表格服务(“ContactsApp”);//此处发生异常
setProtocolVersion(SpreadsheetService.Versions.V3);
试一试{
service.setUserCredentials(“abcd@gmail.com“,“pwd1234”);
}捕获(例外e){
e、 printStackTrace();
}
ArrayList=新建ArrayList();
试一试{
字符串url=
"https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";
//将字符串转换为URL
URL URL字符串=新URL(URL);
//你可以在这里用细胞饲料代替
//列表提要
ListFeed=service.getFeed(urlString,ListFeed.class);
for(ListEntry条目:feed.getEntries()){
ContactsModel contact=新的ContactsModel();
CustomElementCollection elements=entry.getCustomElements();
contact.EmpID=elements.getValue(“Emp Id”);
contact.Name=elements.getValue(“Name”);
contact.personalEmail=elements.getValue(“个人电子邮件”);
contact.workEmail=elements.getValue(“工作电子邮件”);
contact.emergencyContact=elements.getValue(“紧急联系人”);
contact.relation=elements.getValue(“关系”);
列表。添加(联系人);
}
}捕获(IOE异常){
e、 printStackTrace();
}捕获(服务异常e){
e、 printStackTrace();
}
Google ListFeed演示

这个演示是基本的,切中要害的,我认为它包括了所有的ListFeed特性

统一资源定位地址 但是看看它,我认为你的url缺少表单ID

/**********************
 * Standard google urls for spreadsheet service 
 * copied direct from google code
 *********************/
public URL getSpreadsheetsUrl() throws MalformedURLException {
    return new URL(
            "https://spreadsheets.google.com/feeds/spreadsheets/private/full");
}

public URL getSpreadsheetUrl(String key) throws MalformedURLException {
    return new URL(
            "https://spreadsheets.google.com/feeds/spreadsheets/private/full/"
                    + key);
}

public URL getWorksheetsUrl(String key) throws MalformedURLException {
    return new URL("https://spreadsheets.google.com/feeds/worksheets/" + key
            + "/private/full");
}

public URL getWorksheetUrl(String key, String worksheetId)
        throws MalformedURLException {
    return new URL("https://spreadsheets.google.com/feeds/worksheets/" + key
            + "/private/full/" + worksheetId);
}

public URL getCellsUrl(String key, String worksheetId)
        throws MalformedURLException {
    return new URL("https://spreadsheets.google.com/feeds/cells/" + key
            + "/" + worksheetId + "/private/full");
}

public URL getCellUrl(String key, String worksheetId, String cellId)
        throws MalformedURLException {
    return new URL("https://spreadsheets.google.com/feeds/cells/" + key
            + "/" + worksheetId + "/private/full/" + cellId);
}


public URL getTableUrl(String key, String worksheetId, String rowNumber)
        throws MalformedURLException {
    return new URL("https://spreadsheets.google.com/feeds/" + key
            + "/records/" + rowNumber);
}

错误在哪一行。。它还需要应用程序样式的密码,而不是您的真实ID和密码。