Erase inline objects from Docs using Docs API - google-docs-api

I want to delete the inline embedded images when the id is supplied
I have tried with
Docs.Documents.batchUpdate({requests: [{"deletePositionedObject": {"objectId": "kix.b0ejdj9gt8ia"}}]}, doc.getId());
But this will not delete the images inside

Findings
On my replication, the DeletePositionedObjectRequest produces an error as seen below after inserting an embedded image with an objectId:
The DeletePositionedObjectRequest Request:
The Error:
{
"error": {
"code": 400,
"message": "Invalid requests[0].deletePositionedObject: No positioned object with ID: kix.ig5lfhg9lak6",
"status": "INVALID_ARGUMENT"
}
}
This looks like the objectId needed in DeletePositionedObjectRequest is a positioned object & is different from objectId of the inline embedded image.
Recommendation
As an alternative solution, you can use the deleteContentRange instead & adjust it accordingly to your setup.
Test Result:
1. Get the startIndex & endIndex of the embedded inline image on the document.
2. The deleteContentRange request body
Sample document before running the request:
Sample Document after:

Related

Getting a list of all Media in Instagram with Graph API

In my code, I have been pulling the list of media in Instagram using the following URL:
https://graph.facebook.com/{app_id}/media?fields=media_url,{..some fields here...}&limit=10000&access_token={my_access_token}
This was working fine and I didn't touch the code for a month. Now suddenly it gives the error:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (media) on node type (Application)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Aty4vnPpLWfGq9Hj6hQFtZR"
}
}
Nothing in the documentation says that media is no longer available. Graph API version has updated from v14 to v15 since I used it, but the request isn't working on either version.
Access token is fine because other requests are working correctly.
Does anyone have any insights? What alternatives do I have?
I think you are defining an invalid field. Below is a list of fields you can use. Also i suggest you also try instagram account id instead of app_id.
fields=[id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count]
final url:
https://graph.facebook.com/v14.0/{instagram_account_id}/media?fields=id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count&access_token={my_access_token}

YouTube Data API V3 unkownPart "localizations"

I have been trying to fetch all videos from a playlist using YouTube Data API, which worked like a char; next, I wanted to try and filter videos based on languages, so I wanted to try to include the "localizations" part. However, whenever I do, I get a 400 response stating that "localizations" is "unkownPart". From what I could see in the documentation, I should have my GET request structured properly:
`https://youtube.googleapis.com/youtube/v3/playlistItems?part=localizations&part=snippet&maxResults=${limit}&playlistId=${playlistId}&key=${apiKey}`
Error message in postman:
{
"error": {
"code": 400,
"message": "'localizations'",
"errors": [
{
"message": "'localizations'",
"domain": "youtube.part",
"reason": "unknownPart",
"location": "part",
"locationType": "parameter"
}
]
}
}
"localizations" is a direct copy from the documentation. The GET request works fine if I remove it so I'm confident that the problem is either the order or my parameters, or the combinations of parameters in use (though I couldn't find anything about incompatible parameters in the documentation).
Parameters order goes as follows:
localizations
snippet
playlistId
key
EDIT: link to the documentation: https://developers.google.com/youtube/v3/docs/playlists/list
After sending the Issue Report it was discovered that I had been using the wrong API endpoint. Somehow (I can't remember why) I was using the "playlistItem" endpoint which doesn't support "localizations", and needed to shift to using the "playlists" endpoint instead.
Furthermore when using a combination of both "snippet" and "localization", they should be within the same parameter but comma-separated, however, Postman doesn't auto-convert the commas in the parameters to "%2C" and therefore would cause further trouble understanding the requests. Fixing these 2 steps, it now works as intended.

Can't Update Sharepoint Managed Meta Data Field from Microsoft Graph Explorer

I'm trying to update the fields associated with a list item via Graph Explorer, https://developer.microsoft.com/en-us/graph/graph-explorer (or a REST API call). For one of the fields, its value can be one item from a term set (managed meta data). I can see each of the elements in the term set and get each termguid when I visit https://XXX.sharepoint.com/Lists/TaxonomyHiddenList/AllItems.aspx.
I'm trying to do a PATCH request with a URL of something like https://graph.microsoft.com/beta/sites/XXX.sharepoint.com,FOO,BAR/drive/root/children/Test%20Document.txt/listItem/fields (or https://graph.microsoft.com/v1.0/sites/XXX.sharepoint.com,FOO,BAR/drive/list/items/1/fields) to identify the fields associated with a specific item
To update the CakeType field, I've set the request body to the following:
{
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
When I then press the Run Query button, I get an InvalidClientQueryException with a message of "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value."
So, I've been trying to figure out what datatype to specify and how to... In various examples online, I've seen adding a field named __metadata and others adding #odata.type, like CakeType#odata.type for the case here. I've tried adding these lines within the CakeType JSON and outside it, for the whole structure. Neither worked...
{
"CakeType": {
"__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
or
{
"__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
I've also tried using the field name in the type which I thought I saw somewhere...
"__metadata" : {"type" : "SP.Data.CakeType" },
and tried
"CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"CakeType#odata.type" : "SP.Data.CakeType",
"#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
The only things that gave a different error message was when I put "CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" , immediately after the opening { or without the CakeType part within the CakeType...
{
"CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
and
{
"CakeType": {
"#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXXX",
"WssId": -1
}
}
Each gave an error of "A type named 'SP.Taxonomy.TaxonomyFieldValue' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."
This makes me think that I have the right field name but the wrong type...
So... what should I be naming the type so I can update the managed meta data field? or... what must the JSON be if the above structure is so far off... or how can I update the field strictly using the Graph API.
Thanks.
I thought looking at schema extensions might help (GET https://graph.microsoft.com/v1.0/schemaExtensions) but it didn't...
Ultimately, I'm trying to update the managed meta data field from Java with the classes in com.microsoft.graph.... so if I can figure out the right stuff with Graph Explorer, I can then move over to Java. I've seen some examples of such in other languages but can't figure out the right way to do same in Java.
Here is how I was finally able to do this.
First you need the id of the hidden field which is the displayName corresponding to your field CakeType which should be CakeType_0.
I used this REST call to get find the id:
https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items?expand=hidden
This will return all your fields and you want the one with the _0 suffix:
..."displayName": "Cake_0",...
"name": "d39a5181f12f41a483acb1a4e47477b1"...
It is this name id you need to use to update the field.
So then the PATCH call on your item is like this:
https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items/{itemid}
Then the payload syntax is like this:
{"{FieldID}":"{TermNumber};#{Term}|{TermGuid}"}
So it would look like this (assuming Apple is the 4th tag although I think -1 might work there too):
{"d39a5181f12f41a483acb1a4e47477b1":"4;#Apple|3a3ad73f-94ca-4d1e-a25c-XXXX"}
For more than one tag separate them with ;# all within the same quoted string
I was having the same issue, and found this: https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/33421180-support-for-setting-sharepoint-managed-metadata-t
The feature request:
Support for setting SharePoint Managed Metadata (taxonomy) column values and other complex column types on items via the Graph API
The response:
Thank you for your feedback! This work is on the backlog and currently isn’t scheduled. The feature will be updated here once dev work has started. -EY

Album mbId in track's metadata

I am using MusicBrainz to get a track's meta data. I want to get the track's album's mbid. I am doing the following lookup using ISRC code.
https://musicbrainz.org/ws/2/isrc/USRC11600201?fmt=json
But in response I don't get any metadata related to the album of the track. I get the following response:
{
"isrc": "USRC11600201",
"recordings": [
{
"disambiguation": "single remix",
"title": "Cheap Thrills",
"id": "92e27a47-3546-4bc2-a9f7-b19e43d7a531",
"length": 223000,
"video": false
},
{
"length": 218540,
"video": false,
"title": "Cheap Thrills",
"disambiguation": "",
"id": "5845e975-33b4-4b0d-8e74-8f57d128b3d1"
}
]
}
I have tried various combinations of the "inc" sub query parameter as well but nothing works. Please help me out. I am really stuck at this.
Using inc=releases in the URL parameters should be enough to get you the information that you want. However, it seems like there's a bug with MusicBrainz's JSON web service (which is still officially in beta), as you can see in the difference between the XML and JSON end points' output:
https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases&fmt=json (JSON) vs. https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases (XML).
One obvious solution/work-around here would be to switch to using the more mature XML endpoint. If that is not an option, you can use the Recording MBIDs given in the JSON output to look up releases associated with those Recordings, e.g., https://musicbrainz.org/ws/2/recording/5845e975-33b4-4b0d-8e74-8f57d128b3d1?inc=releases&fmt=json (note that inc=releases is also needed here to get the information about the releases, and it actually works when looking up recordings).
So to get the details of the album of a track when I have the ISRC of the track, we need to do the following get request:
https://musicbrainz.org/ws/2/isrc/GBUM71604605?inc=releases
It will give a response in xml. The xml api is more stable click for more details on this
As I need the response in json, we can use a library like xml to json and vice-versa library
As much as I have seen the xml response from the MusicBrainz api is more accurate and gives a lot of information.

How to update YouTube Channel banner using v3 Data Api?

I'm trying to insert a channel banner using the YouTube v3 Data API. I'm using the .net client library. This documentation calls for a 3 step process.
Upload new banner
Extract new banner url from upload response
Set bannerExternalUrl to extracted url and call channel update.
My problem is with step 2. If I check the returned url is null. I've double check in Fiddler that the json response does not contain a Url property or value.
Anyone have an idea on how do the banner upload? Thanks!
var channelBannerResource = new ChannelBannerResource();
var insertMediaUpload = _serviceV3.ChannelBanners.Insert(channelBannerResource, new FileStream("C:\\banner1.png", FileMode.Open, FileAccess.Read), "image/png");
insertMediaUpload.Oauth_token = _accessToken;
var result = insertMediaUpload.Upload();
//banner Url returns null
var bannerUrl = insertMediaUpload.ResponseBody.Url;
Not too sure but, Check this link out (if you haven't already)
https://developers.google.com/youtube/v3/docs/channelBanners
Your code looks OK on a quick look
One thing to watch out for The image must have a 16:9 aspect ratio and be at least 2120x1192 pixels.
Update
OK, it appears that you haven't called the channels update method. Something like this
Channel updateChannelResponse = youtube.channels()
.update("god knows what parameter(s) here")
Check this link out for more details:
https://developers.google.com/youtube/v3/docs/channels/update
Recon after you call this method the URL should be there...I recon...
Update 2...
Yeah your right, I tried the api explorer but couldn't get that to work either:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channelBanners.insert?_h=2&resource=%257B%250A++%2522url%2522%253A+%2522http%253A%252F%252Ffr.upphotos.net%252Fwp-content%252Fuploads%252F2013%252F05%252FFerrari-HD-Widescreen-Large.jpg%2522%250A%257D&
But unfortunately get an error response, weird thing is it's complaining about the 'part' parameter but there is none...could this be a bug in the API, can't imagine many people using this functionality
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "contentDetails",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "contentDetails"
}
}
I was expecting this insert to give the URL, fresh out of ideas here.

Resources