我已经看过很多关于此的文章,但它们似乎已经过时了,例如Google Docs电子表格网址都没有关键参数.我也读过这篇文章: 来自谷歌电子表格的JSON数据
然后我阅读此内容以访问数据 https://developers.google.com/gdata/samples/spreadsheet_sample
我的电子表格位于:https: //docs.google.com/spreadsheets/d/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/edit#gid=0
我试过使用这段代码,我觉得我的密钥或语法有问题,请指导修复.
<script src="http://spreadsheets.google.com/feeds/feed/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/worksheet/public/basic?alt=json-in-script&callback=importGSS"></script>
<script type="text/javascript">
function importGSS(json) {
console.log('finished');
}
</script>
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个将其数据库存储在Google电子表格中的iPhone应用程序.我按照此处的DrEdit示例使用Drive API将纯文本文件读/写到Google云端硬盘.我正在尝试修改示例应用以使用电子表格.我能够上传csv文件并要求Google进行转换.但是,我真正想要的是直接使用mimeType:"application/vnd.google-apps.spreadsheet".我对此非常陌生,如果有人能指出我的例子,那将是非常有帮助的.对于初学者,我想实现以下类似的东西
- (void)uploadSpreadSheetWithThreeCells {
GTLUploadParameters *uploadParameters = nil;
NSString *data = @"cell1,cell2,cell3";
NSData *spreadSheetContent = nil;
/*
How to initialize spreadSheetContent with data?
*/
[GTLUploadParameters uploadParametersWithData:spreadSheetContent
MIMEType:@"application/vnd.google-apps.spreadsheet"];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:self.driveFile
uploadParameters:uploadParameters];
[self.driveService executeQuery:query completionHandler:nil];
}
Run Code Online (Sandbox Code Playgroud)
此外,Google Drive API是否正确使用?最终,我希望能够更新电子表格的选定单元格,而不是上传整个文档.我发现了一些其他选项,如gdata api和spreadsheet api,但似乎Drive API是最新的,它应该包含其他两个的功能?
提前致谢!
我正在尝试使用Javascript访问私人Google电子表格.我已成功获得OAuth2.0授权,可以看到我所有Google云端硬盘文档的列表.我似乎无法做的是进入特定的电子表格.代码如下,函数"retrieveAllFiles"中的相关电子表格代码.其中很多都是从Google教程中挑选出来的.
var clientId = 'working';
var apiKey = 'working';
var scopes = 'https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds';
function handleClientLoad() {
console.log('inside handleClientLoad function');
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
console.log('inside checkAuth function');
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
console.log('finished checkAuth function');
}
function handleAuthResult(authResult) {
console.log('inside handleAuthResult function');
var authButton = document.getElementById('authButton');
authButton.style.display = 'none';
if (authResult && !authResult.error) {
//Access token has been succesfully retrieved, requests can be sent to the API.
apiCalls();
} else {
//No access token could …Run Code Online (Sandbox Code Playgroud) 我想设置电子表格单元格背景颜色和文本大小.我使用这个Java代码将文本设置为单元格,但我找不到如何设置样式的解决方案.
CellData setUserEnteredValue = new CellData()
.setUserEnteredValue(new ExtendedValue()
.setStringValue("cell text"));
Run Code Online (Sandbox Code Playgroud)
有什么解决方案吗?
我按照下面的"Android快速入门"进行操作.
https://developers.google.com/sheets/api/quickstart/android
效果很好.
但该示例将电子表格ID硬编码为现有电子表格.
String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
Run Code Online (Sandbox Code Playgroud)
我需要能够按名称查找现有的电子表格,并存储ID(供以后使用).
我想做这样的事情:
private com.google.api.services.sheets.v4.Sheets sheetsService = null;
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
sheetsService = new com.google.api.services.sheets.v4.Sheets.Builder(
transport, jsonFactory, credential)
.setApplicationName("My Application Name")
.build();
String spreadsheetId = null;
List<Spreadsheet> allSpreadsheets = sheetsService.spreadsheets().getAListOfAllSpreadsheets;
for (Spreadsheet spreadsheet : allSpreadsheets) {
if (spreadsheet.getName().equals("My Sheet")){
// found!
spreadsheetId = spreadsheet.getId();
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢提前!
使用developers.google.com我们创建了api用户并将下载的凭据作为json文件.现在,在我的macbook上gspread身份验证在使用credentials.json时工作正常.当在aws上将相同的配置移动到linux服务器时,它给出403不足的权限错误.
Pip和python版本是一样的.
例外
gspread.v4.exceptions.APIError: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
Run Code Online (Sandbox Code Playgroud)
基本代码
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
client = gspread.authorize(creds)
sheet = client.open('MySheetName').sheet1
Run Code Online (Sandbox Code Playgroud) -我想做的事
我想使用Google Spreadsheet API Java库从Google Spreadsheet获取数据而无需身份验证.Google电子表格随公开发布.我想使用以下方法:com.google.gdata.data.spreadsheet.CustomElementCollection
-问题
CustomElementCollection返回使用身份验证收集数据.但是CustomElementCollection在没有身份验证的情况下返回null.
由于listEntry.getPlainTextContent()显示数据,所以我认为我应该能够以任何方式获取数据.
- 附加源代码
使用身份验证:Auth.java
import java.net.URL;
import java.util.List;
import com.google.gdata.client.spreadsheet.ListQuery;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.CustomElementCollection;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.WorksheetEntry;
public class Auth {
public static void main(String[] args) throws Exception{
String applicationName = "AppName";
String user = args[0];
String pass = args[1];
String key = args[2];
String query = args[3];
SpreadsheetService service = new SpreadsheetService(applicationName);
service.setUserCredentials(user, pass); //set client auth
URL entryUrl = new URL("http://spreadsheets.google.com/feeds/spreadsheets/" + key);
SpreadsheetEntry spreadsheetEntry …Run Code Online (Sandbox Code Playgroud) java google-authentication google-sheets google-spreadsheet-api
我找到了代码来列出Google表格中所有表格的名称(从这里开始):
function SheetNames() { // Usage as custom function: =SheetNames( GoogleClock() )
try {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
var out = new Array( sheets.length+1 ) ;
//out[0] = [ "Name" , "gid" ];
for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] = [sheets[i-1].getName()];
return out
}
catch( err ) {
return "#ERROR!"
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何修改脚本以跳过前两个工作表名称并开始填充调用脚本的单元格中的列表?
我尝试更改为var i = 1,var i = 3并确实跳过前两个工作表名称,但它也创建为空白单元格.如何跳过前两个工作表名称而不创建任何空白单元格?
我创建了一个在30分钟后触发的函数,我想传递一些参数.我有一个库返回carHistory,我的电子表格从我调用库函数.
Library1.gs
function carHistory(number,maker)
{
// code logic
}
function startEvery30mins_CarHistory(number,maker)
{
//This function works
carHistory(number,maker);
// how to trigger this with parameter.
ScriptApp.newTrigger("carHistory")
.timeBased()
.everyMinutes(30)
.create();
}
Run Code Online (Sandbox Code Playgroud)
在我的SpreadSheet中
Code.gs:
function startOnce(){
Library1.carHistory("US-xxx","Honda");
}
function startEvery30mins(){
Library1.startEvery30mins_CarHistory("US-xxx","Honda");
}
Run Code Online (Sandbox Code Playgroud)
编辑:
Code.gs:我尝试使用PropertiesService,但仍然无法正常工作
function startOnce(){
var uProps = PropertiesService.getUserProperties();
uProps.setProperty('Maker', 'Honda');
uProps.setProperty('Number', 'US-xxx');
Library1.carHistory();
}
Run Code Online (Sandbox Code Playgroud)
图书馆 :
function carHistory()
{
// Fetch Parametr
var getProps=PropertiesService.getUserProperties();
var c_Maker= getProps.getProperty('Maker');
var c_Number=getProps.getProperty('Number');
// code logic
}
Run Code Online (Sandbox Code Playgroud)
function startEvery30mins_CarHistory()
{
ScriptApp.newTrigger("carHistory")
.timeBased()
.everyMinutes(30) …Run Code Online (Sandbox Code Playgroud) 我有一种情况,脚本正在获取输入数据并将其发送到电子表格.过了一会儿,这个电子表格变得太大了.
现在我们必须手动将项目从主电子表格移动到新的电子表格.原因是并非每个人都熟悉代码并且愿意更改代码中的ID.
我想知道是否有办法按名称打开电子表格.如果没有,是否有更好的方法来实现我们需要的东西(如上所述)
java ×2
javascript ×2
android ×1
gdata-api ×1
google-apps ×1
gspread ×1
ios ×1
json ×1
oauth-2.0 ×1
python ×1