https://developers.google.com/apps-script/guides/rest/api#parameter_and_return_types
When using the Google Execution Api for Java, the ID of the spreadsheet isn't very easy to understand. Here is the code snippet:
// Initialize parameters for that function.
String sheetId = "<ENTER_ID_OF_SPREADSHEET_TO_EXAMINE_HERE>";
List<Object> params = new ArrayList<Object>();
params.add(sheetId);
Any Ideas on how to locate this. I run the Sheets api to return the id of a SpreadSheet but it returns a link, and when I use the https://spreadsheets.google.com/feeds/spreadsheets/STRING or just the STRING itself I still get:
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Requested entity was not found.",
"reason" : "notFound"
Found this deep inside the Apps Script API reference.
A spreadsheet ID can be extracted from its URL. For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".
https://developers.google.com/sheets/api/guides/concepts
states that:
Every API method requires a spreadsheetId parameter which is used to identify which spreadsheet is to be accessed or altered. This ID is the value between the "/d/" and the "/edit" in the URL of your spreadsheet. For example, consider the following URL that references a Google Sheets spreadsheet:
https://docs.google.com/spreadsheets/d/1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps/edit#gid=0
The ID of this spreadsheet is 1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps.
So I just pulled up my spreadsheet and looked at the URL to find my ID.
Hope this helps!
I just created a hyperlink to the sheets and then copied that hyperlink to a text file and the link line shows the GID.
https://docs.google.com/spreadsheets/d/1TxNHS6vuse1is2Mw_hUs9wTDM6f095Y6pKLeltUfNzQ/edit#gid=1049871492
Then I created a pull down list in A52 and then made =IF() logic to go to the GIDs to go to those sheets.
=IF(A52="47QTCK18D0001",HYPERLINK("#gid=0","47QTCK18D0001"),IF(A52="47QTCK18D0002",HYPERLINK("#gid=1049871492","47QTCK18D0002") ....
Related
In api automation, let's consider below code to hit the api and get response.
Response res= given().
formParam("email", "value").
formParam("password", "value").
formParam("action", "login").
header("token","value").
when().post("MyResource").then().assertThat().statusCode(200).extract().response();
Actually in the above code we're just building an api with formParams, header and resource with post request right!
so, there we have created 3 formParm manually and passed the values right? now i want that to added automatically based on no of parameters that we have from an excel sheet.
Thing is these parameters can be deleted or new parameters gets added in future, so that's why i want to add those dynamically from an excel sheet data.
how i can do that? any suggestions?
If i've understood you right, you want to have the parameters on the spreadsheet to use dynamically and on runtime.
To do that, you'll need to:
Read the spreadsheet file and get the parameters contained in a data structure such as a Map<String,String>, in which, the key is the field and the value is... the value :P
Iterate upon the data structure selected and set the formParam generically
final RequestSpecification given = given();
for(final Map.Entry<String,String> entry : map.entrySet()) {
given.formParam(entry.getKey(), entry.getValue());
}
final Response res = given.other_things() ...
I hope it helps, but keep in mind the use of Map is not necessary. Choose the data structure more appropriate to your situation!
I am trying to retrieve metadata of a video file present in my google drive. I can access all the information related to that file (like size, mimetype, etc.). But, when I am trying to retrieve metadata of that video file I am getting a null value. Could you please tell me how can I retrieve metadata of a video file. Thanks in advance.
VideoMediaMetadata video_Media_MetaData=file.getVideoMediaMetadata();
AFAIK, a successful HTTP request using Files: list will return a response body which includes videoMediaMetadata in the following structure:
{
"kind": "drive#fileList",
"nextPageToken": string,
"incompleteSearch": boolean,
"files": [
"videoMediaMetadata": {
"width": integer,
"height": integer,
"durationMillis": long
},
"isAppAuthorized": boolean
]
}
However, please note that, as described in Files documentation, videoMediaMetadata is
Additional metadata about video media. This may not be available immediately upon upload.
Thus, it will return null for none as mentioned here.
With this, you may want to try Files: update to update a file's metadata and/or content with patch semantics.
I am trying to access Google spreadsheets using a spreadsheet example. When I run the example code it worked fine. I just change the SpreadsheetId and range. It started giving me:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Unable to parse range: Class Data!A2:A4",
"reason" : "badRequest"
} ],
"message" : "Unable to parse range: Class Data!A2:A4",
"status" : "INVALID_ARGUMENT"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at poc.mainPOC.main(mainPOC.java:157)
Below is the code:
String spreadsheetId = "my spread sheet ID";
String range = "Class Data!A2:A4";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
Try replacing Class Data!A2:A4 with A2:A4
If you look at the sheet itself you will notice that the Worksheet is titled "Class Data". So just put the name of your sheet where is says "Class Data". Example:
String range = "SheetName!A1:C";
String range = "Class Data!A2:A4";
The Class Data is your worksheet's name, FYI: the name on the tab at the bottom, the default one is "Sheet1". Replace Class Data with the one you want to work with.
I was trying to add some data to a sheet named Emmett that did not existed yet and was receiving this error:
Error: Unable to parse range: Emmet!A2:C12
I had to manually create the sheet named Emmett in the spreadsheet and then it worked like a charm.
I ran into this error when I had a typo in the name of the tab. In your case "Class Data" didn't match the name of the tab
In my case there was an extra space in the google sheet while I was trimming the sheet name at my end. Once I removed the trimming logic, everything worked fine.
Something that I learned was that If the column name doesn't exist yet, this command won't be able to find it. You need to make sure the column you're writing to already exists -- I did this manually from the google sheet.
Hey i am doing a project of data retrieval from tweets from twitter, i am collecting tweets from certain kinds of events, few of the post contains some links, few are expanded and few are shorten, i want to save link from each tweets to my mysql database. I have found code for expanding url, someone please tell me will this work for every shorten url.
for (URLEntity urle : status.getURLEntities()) {
System.out.println(urle.getDisplayURL());
System.out.println(urle.getExpandedURL());
}
With that code you will print the url twice, from the Javadoc
getDisplayURL
Returns: the display URL if mentioned URL is shorten, or null if no shorten URL was mentioned.
So, for every URLEntity you will need to print the expanded URL if it's shortened
for (URLEntity urle : status.getURLEntities()) {
if(urle.getExpandedURL()){System.out.println(urle.getExpandedURL());}
else {System.out.println(urle.getDisplayURL());}
}
Or in you case, save them to a database.
I am writing a code in which I need to access a particular column of a spreadsheet, already uploaded on my GDrive. I have found the Java API that is required for my project.
https://developers.google.com/google-apps/spreadsheets/#fetching_specific_rows_or_columns
I have have already installed : Mercurial, Maven and Google PlugIn for eclipse, as well.
Now when I run my code, the following error comes : " The type com.google.gdata.client.GoogleService cannot be resolved. It is indirectly referenced from required .class files".
According to me this error is might be because of the path/URL given in the google API to access a particular spreadsheet :
URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
PLEASE HELP!!
Do you have the required Google Data API Client libraries downloaded or not? If not, make sure those libraries are downloaded and check this link
It seems this is the dependency: http://mvnrepository.com/artifact/com.google.gdata/core/1.47.1
Hope that helps!
The Google Spreadsheets API documentation (Fetching specific rows or columns) suggests the following...being worksheet the specific worksheet instance of your spreadsheet, and let's say 6 the column list of values that you want to get:
URL cellFeedUrl = new URI(worksheet.getCellFeedUrl().toString() +
"?min-row=2&min-col=6&max-col=6").toURL();
CellFeed cell = service.getFeed(cellFeedUrl, CellFeed.class);
for(CellEntry eachCellEntry : cell.getEntries()){
// prints value of each cell in column 6 but the title
log.info(eachCellEntry.getCell().getValue());
}
I don't like the passing of the hard coded arguments in a String manually for the URL when using CellFeed...like min-row, min-col, max-col...I am trying to find a better way to do this, perhaps using a query.