Adding image to question item in the new google form rest api - google-forms-api

Is it possible to use image in the google drive? If yes, how? I have tried using https://drive.google.com/uc?id= + id, but failed.
error": {
"code": 400,
"message": "Failed to fetch image from source_uri: https://drive.google.com/uc?id=xxxxxxxxxxxxxxxxxxxx",
"status": "INVALID_ARGUMENT"
}
Image
{
"contentUri": string,
"altText": string,
"properties": {
object (MediaProperties)
},
"sourceUri": string
}

I use this form
update = {
"requests": [{
{
"createItem": {
"item": {
"imageItem": {
"image": {
"sourceUri": https://drive.google.com/uc...
}
}
},
"location": {
"index": 0
}
},
},
]
}
service_form.forms().batchUpdate(
formId=form_id, body=update).execute()
Doc https://developers.google.com/forms/api/reference/rest/v1/forms/batchUpdate

Related

Api Connect v10 map json message with object array to object using foreach or similar (map policy)

I'm new to API Connect, and I haven't been able to find the correct mapping to pass from an array of objects to an object, evaluating its content.
I explain:
I have as input a json like this:
{
"methodCall": {
"methodName": {
"$": "ThisIsTheMethodName"
},
"params": {
"param": {
"value": {
"array": {
"data": {
"value": {
"struct": {
"member": [
{
"name": {
"$": "message"
},
"value": {
"string": {
"$": "Some text to send to client"
}
}
},
{
"name": {
"$": "phone"
},
"value": {
"string": {
"$": "9876543120124"
}
}
},
{
"name": {
"$": "date"
},
"value": {
"string": {}
}
},
{
"name": {
"$": "appid"
},
"value": {
"string": {
"$": "Application Identificator"
}
}
},
{
"name": {
"$": "costCenter"
},
"value": {
"string": {
"$": "102030"
}
}
},
{
"name": {
"$": "filled"
},
"value": {
"string": {
"$": "filledString"
}
}
}
]
}
}
}
}
}
}
}
}
}
and I need to generate this json output from the mapping:
{
"phoneNumberSMS":"983849780",
"message":"Some text to send to client",
"date": "2022-10-04T15:30:00",
"appId":"Application Identificator",
"costCenter":"102030",
"filled":"filledString" }
I have tried with the following configuration, but without success:
On the YAML
actions:
- set: output.phoneNumberSMS
foreach: input.methodCall.params.param.value.array.data.value.struct.member.value.string
from:
- input.methodCall.params.param.value.array.data.value.struct.member.name.$
- input.methodCall.params.param.value.array.data.value.struct.member.value.string.$
values: |-
var retValue1 = '';
if($(input.methodCall.params.param.value.array.data.value.struct.member.name.$) == 'phone'){
retValue1=input.methodCall.params.param.value.array.data.value.struct.member.value.string.$;
}
retValue1;
I appreciate your help !!
I solve this in two phases of mapping:
Create an array called members, where each node is of type member, which has name and value properties.
This 'members' array is the receiver of the data coming from the request.
In the second phase of the mapping, I took the output variable from the previous mapping (of type members) and assigned it to message.body.
This with the aim of getting rid of the field names with a dollar symbol ($), so the mapping will not give any error for not recognizing it.

Google ads rest api cannot create a campaign "MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT"

I'm trying to create Google Ads campaigns using the Google Adwords API and getting this error MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT
I'm calling this endpoint:
https://googleads.googleapis.com/v10/customers/customerID/campaigns:mutate
with the payload:
{
"operations": [
{
"create": {
"status": "PAUSED",
"advertisingChannelType": "SEARCH",
"advertisingChannelSubType": "SEARCH_EXPRESS",
"paymentMode": "CONVERSIONS",
"name": "TestCampaign",
"campaignBudget": "customers/${customerID}/campaignBudgets/${budgetId}",
"biddingStrategyType": "COMMISSION",
}
}
]
}
Here is the response:
"errors": [
{
"errorCode": {
"operationAccessDeniedError": "MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT"
},
"message": "A mutate action is not allowed on this resource, from this client.",
"trigger": {
"stringValue": ""
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "advertising_channel_sub_type"
}
]
}
},
{
"errorCode": {
"operationAccessDeniedError": "OPERATION_NOT_PERMITTED_FOR_CAMPAIGN_TYPE"
},
"message": "This operation is not permitted on this campaign type",
"trigger": {
"stringValue": "SEARCH(SEARCH_EXPRESS)"
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "payment_mode"
}
]
}
}
],

Invalid ReplaceNamedRangeContent request

I can successfully create a name range using batchUpdate api, however, replaceNameRangeContent gives the following error:
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
The request for this was:
{ "requests": [ { "replaceNamedRangeContent": { "namedRangeId": "kix.ydbik9q4xmna", "text": "" } } ] }
Am I using the API properly? I created the name range giving start/endindex and naming it. It creates the NameRangeId that I used in the replace content post.
There was content in the index range above. However, below is a sample doc structure for an empty doc (with doc styles, etc. omitted). I tried a
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 1,
"endIndex": 2
},
"name": "ApplicantName"
}
}
]
}
followed by
{
"requests": [
{
"replaceNamedRangeContent": {
"namedRangeId": "kix.f7g9w0sr3kyp",
"text": "Applicant Name"
}
}
]
}
and get the same error. But when doing the create named range it would not accept any start/end index besides 1 and 2.
I must not understand the actual intent of named ranges!
Sample:
{
"title": "Test mule",
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT",
"sectionType": "CONTINUOUS"
}
}
},
{
"startIndex": 1,
"endIndex": 2,
"paragraph": {
"elements": [
{
"startIndex": 1,
"endIndex": 2,
"textRun": {
"content": "\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT"
}
}
}
]
}
I can reproduce your error when creating a named range with "startIndex": 0
Mind that indices for paragraphs (and thus text) in Google Docs refer to the position of a character in the text and start with 1.
So if you create a name range specifying the indices correctly, you will not get the error mesage
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
Sample request for creating named ranges:
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 5,
"endIndex": 7
},
"name": "test3"
}
}
]
}

elasticseach How to add search type in request body

I have a query where I am using search_type as
GET /test_videos/_search?search_type=dfs_query_then_fetch&explain=true
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title"]
}
}
}
}
}
which works fine and gives the result I want.
I can also specify the explain in the body like this:
GET /test_claim_videos/_search?search_type=dfs_query_then_fetch
{ "explain" : true,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
}
}
}
}
}
But I want to specify the search_type as dfs_then_fetch inside the body.
If I do
GET /test_claim_videos/_search
{ "search_type" : "dfs_query_then_fetch",
"explain" : true,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
}
}
}
}
}
It raises error:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Unknown key for a VALUE_STRING in [search_type].",
"line": 1,
"col": 19
}
],
"type": "parsing_exception",
"reason": "Unknown key for a VALUE_STRING in [search_type].",
"line": 1,
"col": 19
},
"status": 400
}
Why can't I specify search type in body here and how to fix that? I need it to be in body as I am using a third party gem chewy which doesn't allow to pass URL.
Unfortunately you have no ability to do it. You can read more in documentation:
Out of the above, the search_type and the request_cache must be passed as query-string parameters.

Check if Array exists in JSON file - iOS

I have an iOS application which parses a JSON feed provided by Google Plus. This JSON feed contains links, titles, etc for posts on a Google Plus profile.
The JSON file in certain parts has an array called "attachments" and that array has the image URL which I am parsing.
The problem is that that array is not always present, so sometime its available with the image URL and sometime its not even there.
As a result of this, when I parse for the image URL my iOS application crashes because the array it is looking for is not always present.
So how can I test to see if the array is present before deciding to parse for the image URL. I tried to make a simple if-statement, but it doesn't seem to work. Here it is:
if ([[[episodes objectAtIndex:index] valueForKey:#"object"] valueForKey:#"attachments"] == [NSNull null]) {
NSLog("No image to parse.");
}
else {
// parse image link
}
Here is the JSON file:
{
"kind": "plus#activity",
"etag": "\"9Q4kEgczRt3gWehMocqSxXqUhYo/uQcxIDsySGhlI5hMFHcxjuBhM9k\"",
"title": "",
"published": "2013-02-24T22:30:25.159Z",
"updated": "2013-02-24T22:30:25.159Z",
"id": "z13jgdihsvnytdttc23hxdz5ypfsjnzsb",
"url": "https://plus.google.com/102757352146004417544/posts/7psQLdwS2F7",
"actor": {
"id": "102757352146004417544",
"displayName": "Daniel Sadjadian",
"url": "https://plus.google.com/102757352146004417544",
"image": {
"url": "https://lh4.googleusercontent.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAALQ/2nt32bqYBtM/photo.jpg?sz=50"
}
},
"verb": "post",
"object": {
"objectType": "note",
"content": "",
"url": "https://plus.google.com/102757352146004417544/posts/7psQLdwS2F7",
"replies": {
"totalItems": 0,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z13jgdihsvnytdttc23hxdz5ypfsjnzsb/comments"
},
"plusoners": {
"totalItems": 0,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z13jgdihsvnytdttc23hxdz5ypfsjnzsb/people/plusoners"
},
"resharers": {
"totalItems": 0,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z13jgdihsvnytdttc23hxdz5ypfsjnzsb/people/resharers"
},
"attachments": [
{
"objectType": "video",
"displayName": "SGU - The Game Has Changed!",
"content": "Send this video to your friends to spread the word about the upcoming SyFy marathon. This very well may be our last chance to save the show. If you're in the...",
"url": "http://www.youtube.com/watch?v=WtHusm7Yzd4",
"image": {
"url": "https://lh3.googleusercontent.com/proxy/z9shhK2d39jM2P-AOLMkqP2KMG2DjipCWlcPeVPaRvHkfj-nmxkxqZfntAVMoV88ZOuroRHIvG4qs-K0SaMjQw=w506-h284-n",
"type": "image/jpeg",
"height": 284,
"width": 506
},
"embed": {
"url": "http://www.youtube.com/v/WtHusm7Yzd4?version=3&autohide=1",
"type": "application/x-shockwave-flash"
}
}
]
},
"provider": {
"title": "Google+"
},
"access": {
"kind": "plus#acl",
"description": "Public",
"items": [
{
"type": "public"
}
]
}
},
Thanks for your time, Dan.
UPDATE:
Just assign that to array and check the array is nil.
NSMutableArray *attachments = [[[episodes objectAtIndex:index] valueForKey:#"object"] valueForKey:#"attachments"];
if (!attachments) {
NSLog("No image to parse.");
}
This will work.
I don't see the problem (please post your error details) but when dealing with JSON, I like to use a category IfNullThenNil. Your code would look like:
if ( [ [ episodes[index] valueForKeyPath:#"object.attachments" ] ifNullThenNil ]
{
// parse image link
}
else
{
NSLog(#"No image to parse.\n");
}
Here's the category on NSObject/NSNull
#implementation NSObject (IfNullThenNil)
-(id)ifNullThenNil
{
return self ;
}
#end
#implementation NSNull (IfNullThenNil)
-(id)ifNullThenNil
{
return nil ;
}
#end

Resources