Getting names from geo_target_constant in a Ad report - google-ads-api

I am using ads API for getting the spends based on state names of USA.
The below query gives segments.geo_target_state will be returned as an ID instead of name
How can I combine this query with
SELECT
geo_target_constant.name,
geo_target_constant.canonical_name
FROM geo_target_constant
WHERE geo_target_constant.id = <<OBTAINED ID FROM THE BELOW QUERY>>
curl "https://googleads.googleapis.com/v10/customers/${CUSTOMER_ID}/googleAds:searchStream" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"query": "
SELECT
campaign.name,
segments.geo_target_state,
metrics.cost_micros
FROM geographic_view
WHERE
geographic_view.location_type = LOCATION_OF_PRESENCE
AND segments.date BETWEEN 20220101 AND 20220430
"
}'
That is geoTargetConstants/21136 must be decoded to
"name": "New Jersey",
"results": [
{
"campaign": {
"resourceName": "customers/1234/campaigns/1234",
"name": "Display - macines - Leads Display Campaign Test - AA"
},
"metrics": {
"costMicros": "66664821"
},
"segments": {
"geoTargetState": "**geoTargetConstants/21136**"
},
"geographicView": {
"resourceName": "customers/6383148790/geographicViews/2840~LOCATION_OF_PRESENCE"
}
},

If you want to use the API to lookup the geo target constant name you will have to issue another search request using the query you provided.
This is likely okay in one off scenarios but breaks down quickly if you need to retrieve multiple geo target constants.
What I have do to resolve this is pull the list of geo targets, see: https://developers.google.com/google-ads/api/reference/data/geotargets, and store them locally in a database. Then I can pull the name from a must faster source.

Related

How to Get Hyperlinks Using Google Sheets API v4

I am trying to access a hyperlink using the v4 API ValueRenderOption param (valueRenderOption=FORMULA). I have tried with both python's gsheets and cURL. Either way, I cannot seem to get the formula that will show a hyperlink. Below is a screenshot of the spreadsheet; note the cell containing the value 2 has its formula shown, as expected, but that the hyperlink to https://example.com is shown as "sup". Is there a new way that we are supposed to access the contents of hyperlinks?
gsheets:
print(worksheet.acell('A2', value_render_option="FORMULA").value)
# sup
cURL:
URL="https://sheets.googleapis.com/v4/spreadsheets/$SHEET_ID/values/%27Sheet1%27%21A2"
curl -X GET "$URL?valueRenderOption=FORMULA" -H "Authorization: Bearer $TOKEN"
# output
{
"range": "Sheet1!A1:Z1001",
"majorDimension": "ROWS",
"values": [
[
"Name",
"Other"
],
[
"sup",
"word"
],
[
"k",
100
],
[
"=AVERAGE(1,2,3)",
"k"
]
]
}
I believe your goal as follows.
You want to retrieve a hyperlink which was set to a cell on Google Spreadsheet.
In this case, in the current stage, the hyperlink can be retrieved using the method of "spreadsheets.get" in Sheets API. And, it is required to use the field parameter for this request. By this, the hyperlink can be retrieved. The sample curl command is as follows.
As the sample situation, it supposes that the URL is set to a cell "A1" of "Sheet1" in Google Spreadsheet.
Sample curl command:
curl \
'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEETID]?ranges=Sheet1!A1&fields=sheets(data(rowData(values(hyperlink))))' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
Result:
{
"sheets": [
{
"data": [
{
"rowData": [
{
"values": [
{
"hyperlink": "https://example.com/"
}
]
}
]
}
]
}
]
}
For gspread:
At gspread, requests library is used as follows. The access token is retrieved from credentials of gspread.authorize(credentials).
gc = gspread.authorize(credentials)
access_token = credentials.access_token
url = 'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEETID]?ranges=Sheet1!A1&fields=sheets(data(rowData(values(hyperlink))))'
res = requests.get(url, headers={'Authorization': 'Bearer ' + access_token})
print(res.json())
Result:
{'sheets': [{'data': [{'rowData': [{'values': [{'hyperlink': 'https://example.com/'}]}]}]}]}
Note:
In this sample, sheets(data(rowData(values(hyperlink)))) is used as fields. About this, you can also use sheets. In this case, other values are included in the response values.
At the sample, Sheet1!A1 is used as the range. So please modify this range for your actual situation.
In the current stage, when a hyperlinks is set to a part of texts in a cell and the several hyperlinks are set to a cell, unfortunately, those cannot be directly retrieved using Sheets API. At that time, as the current workaround, it is required to use Google Apps Script. Ref Please be careful this.
References:
Method: spreadsheets.get

Retrieves a list of apps that results of searching by the given term on app store or iTunes store

I am using Node.js module to scrape application data from the iTunes/Mac App Store. My purpose is find then app ranking in search result for particular keyword search.
https://github.com/facundoolano/app-store-scraper
Till today, This module was giving proper app ranking on search results by keyword but suddenly It completely shows different search result than app store in iPhone or Mac.
Does anyone know that There are any changes from apple side?
Module uses below apple url to find the search result.
const BASE_URL = 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/search?clientApplication=Software&media=software&term=';
Does any changes in above URL?
Here is the official api documentation for itunes search api - https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/
Here is an example below for the search you are trying to do:
curl -X GET \
'https://itunes.apple.com/search?clientApplication=Software&media=software&term=Misfits%20Emoji' \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Host: itunes.apple.com' \
-H 'Postman-Token: 06880666-0bb8-4b43-80ed-53e4300444cd,004c0b3c-dffd-4b3d-90e3-e36167e2a127' \
-H 'User-Agent: PostmanRuntime/7.20.1' \
-H 'cache-control: no-cache'
For the example, I have used this application to search https://apps.apple.com/us/app/misfits-emoji/id1172889389 and it is the first item returned in the response.
Response:
{
"resultCount": 1,
"results": [{
"artistViewUrl": "https://apps.apple.com/us/developer/fan-si-inc/id932552952?uo=4",
"artworkUrl60": "https://is2-ssl.mzstatic.com/image/thumb/Purple71/v4/f5/ac/81/f5ac813b-2c60-5739-023d-fca28a4b5fb5/source/60x60bb.jpg",
"artworkUrl100": "https://is2-ssl.mzstatic.com/image/thumb/Purple71/v4/f5/ac/81/f5ac813b-2c60-5739-023d-fca28a4b5fb5/source/100x100bb.jpg",
"screenshotUrls": ["https://is2-ssl.mzstatic.com/image/thumb/Purple71/v4/95/8b/4c/958b4c46-b4d8-f035-d723-ef764131a1f9/pr_source.png/392x696bb.png", "https://is3-ssl.mzstatic.com/image/thumb/Purple71/v4/ab/c0/a2/abc0a2f7-30c3-6f4f-2fa9-f2ccf4b15912/pr_source.png/392x696bb.png"],
"ipadScreenshotUrls": [],
"appletvScreenshotUrls": [],
"artworkUrl512": "https://is2-ssl.mzstatic.com/image/thumb/Purple71/v4/f5/ac/81/f5ac813b-2c60-5739-023d-fca28a4b5fb5/source/512x512bb.jpg",
"isGameCenterEnabled": false,
"advisories": [],
"supportedDevices": ["iPad2Wifi-iPad2Wifi", "iPad23G-iPad23G", "iPhone4S-iPhone4S", "iPadThirdGen-iPadThirdGen", "iPadThirdGen4G-iPadThirdGen4G", "iPhone5-iPhone5", "iPodTouchFifthGen-iPodTouchFifthGen", "iPadFourthGen-iPadFourthGen", "iPadFourthGen4G-iPadFourthGen4G", "iPadMini-iPadMini", "iPadMini4G-iPadMini4G", "iPhone5c-iPhone5c", "iPhone5s-iPhone5s", "iPadAir-iPadAir", "iPadAirCellular-iPadAirCellular", "iPadMiniRetina-iPadMiniRetina", "iPadMiniRetinaCellular-iPadMiniRetinaCellular", "iPhone6-iPhone6", "iPhone6Plus-iPhone6Plus", "iPadAir2-iPadAir2", "iPadAir2Cellular-iPadAir2Cellular", "iPadMini3-iPadMini3", "iPadMini3Cellular-iPadMini3Cellular", "iPodTouchSixthGen-iPodTouchSixthGen", "iPhone6s-iPhone6s", "iPhone6sPlus-iPhone6sPlus", "iPadMini4-iPadMini4", "iPadMini4Cellular-iPadMini4Cellular", "iPadPro-iPadPro", "iPadProCellular-iPadProCellular", "iPadPro97-iPadPro97", "iPadPro97Cellular-iPadPro97Cellular", "iPhoneSE-iPhoneSE", "iPhone7-iPhone7", "iPhone7Plus-iPhone7Plus", "iPad611-iPad611", "iPad612-iPad612", "iPad71-iPad71", "iPad72-iPad72", "iPad73-iPad73", "iPad74-iPad74", "iPhone8-iPhone8", "iPhone8Plus-iPhone8Plus", "iPhoneX-iPhoneX", "iPad75-iPad75", "iPad76-iPad76", "iPhoneXS-iPhoneXS", "iPhoneXSMax-iPhoneXSMax", "iPhoneXR-iPhoneXR", "iPad812-iPad812", "iPad834-iPad834", "iPad856-iPad856", "iPad878-iPad878", "iPadMini5-iPadMini5", "iPadMini5Cellular-iPadMini5Cellular", "iPadAir3-iPadAir3", "iPadAir3Cellular-iPadAir3Cellular", "iPodTouchSeventhGen-iPodTouchSeventhGen", "iPhone11-iPhone11", "iPhone11Pro-iPhone11Pro", "iPadSeventhGen-iPadSeventhGen", "iPadSeventhGenCellular-iPadSeventhGenCellular", "iPhone11ProMax-iPhone11ProMax"],
"kind": "software",
"features": [],
"contentAdvisoryRating": "4+",
"trackCensoredName": "Misfits Emoji",
"languageCodesISO2A": ["EN"],
"fileSizeBytes": "32731136",
"sellerUrl": "http://fan.si",
"averageUserRatingForCurrentVersion": 3.5,
"userRatingCountForCurrentVersion": 4,
"trackViewUrl": "https://apps.apple.com/us/app/misfits-emoji/id1172889389?uo=4",
"trackContentRating": "4+",
"currentVersionReleaseDate": "2016-11-21T17:30:21Z",
"releaseNotes": "Updated icons.",
"isVppDeviceBasedLicensingEnabled": true,
"formattedPrice": "$0.99",
"trackId": 1172889389,
"trackName": "Misfits Emoji",
"primaryGenreName": "Entertainment",
"genreIds": ["6016", "6002"],
"primaryGenreId": 6016,
"sellerName": "Fansi Inc",
"releaseDate": "2016-11-17T18:12:35Z",
"minimumOsVersion": "8.0",
"currency": "USD",
"version": "1.0.1",
"wrapperType": "software",
"artistId": 932552952,
"artistName": "Fan.si Inc.",
"genres": ["Entertainment", "Utilities"],
"price": 0.99,
"description": "Social Club Misfits present this very rare emoji collection featuring dozens of new emoticon pictures and exclusive gifs. Satisfy all you communication needs with pizza, pugs, pineapples, and so much more!",
"bundleId": "si.fan.socialmisfits-emoji"
}]
}

Cumulocity - Send Measurement/Alarm/Event using external ID via HTTP

I've been recently exploring Cumulocity and managed to use the external ID to send data (measurements/alarms/events) via MQTT. Its well documented and pretty straight forward.
But I cant find how to send data (measurement/alarm/event) using ExternalID instead of source.
For example, here is how POST of a measurement looks like if you know ClientID of device:
curl -X POST \
https://myTenant.cumulocity.com/measurement/measurements \
-H 'Accept: application/vnd.com.nsn.cumulocity.measurement+json' \
-H 'Authorization: Basic mytoken' \
-H 'Content-Type: application/json' \
-d '{
"c8y_TemperatureMeasurement": {
"T": {
"value": 25,
"unit": "C" }
},
"time":"2019-03-07T10:03:14.000+11:00",
"source": {
"id":"1234567" },
"type": "c8y_TemperatureMeasurement"
}'
Is there a way to replace that "source": {"id":"1234567" }, with external ID?
What would the request look like?
As of today, this is not possible:
Instead you have to first convert the externalID to the source id once (e.g. when the device is booted its done as first actions). Afterwards send all requests (e.g. POSTs to create measurements/alarms/events) using this retrieved sourceID.
This is also described in the Device SDK for HTTP here: https://cumulocity.com/guides/device-sdk/rest#step-1-check-if-the-device-is-already-registered .
Thanks for the good feedback on the documentation!

YouTube artist charts api?

Does YouTube expose it's artist charts via api or is there a way to get the charts data using the youtube api?
I'm talking about the charts data here https://artists.youtube.com/charts/videos
I don't think it's possible using the official Youtube API, if we look at https://artists.youtube.com/charts/videos, it uses YouTube Internal API (InnerTube) with a specific API key (registered to use youtubei API which is not available to developers)
Of course it's a hack just FYI
The API key has https://artists.youtube.com configured as referer, adding the custom header: x-referer:https://artists.youtube.com make it works :
curl -H 'Content-Type: application/json' \
-H "x-referer:https://artists.youtube.com" \
"https://content.googleapis.com/youtubei/v1/browse?alt=json&key=AIzaSyCzEW7JUJdSql0-2V4tHUb6laYm4iAE_dM" \
-d '{
"context": {
"client": {
"clientName": "WEB_MUSIC_ANALYTICS",
"clientVersion": "0.2",
"theme": "MUSIC",
"hl": "en",
"gl": "FR",
"experimentIds": []
},
"capabilities": {
},
"request": {
"internalExperimentFlags": []
}
},
"browseId": "FEmusic_analytics",
"query": "chart_params_type=WEEK&perspective=CHART&flags=viral_video_chart&selected_chart=VIRAL_VIDEOS"
}'
If it doesn't work, get the API key from the network log of https://artists.youtube.com
In the query field, you can modify the selected_chart parameter :
all video :
selected_chart=VIDEOS
viral videos chart :
selected_chart=VIRAL_VIDEOS
artists :
selected_chart=ARTISTS
tracks :
selected_chart=TRACKS

Marketo REST API: Associating a lead with a program

I've searched high and low and don't believe this is possible, but before giving up, thought I'd ask on here. Is there any way that anyone's found - roundabout or not - to create a lead and associate it with a program in Marketo via their REST API?
Thanks!
Why not using a smart campaign that automatically associate leads with the relevant program?
You can create some custom field in MLM (for example: "Associate with Program") and when you create a new lead with the API add some value in this field, i.e "associateWithProgram" : "program123".
Then, in MLM create a campaign that is being triggered whenever a new lead is created and the associateWithProgram field is not empty.
The flow will be to add the lead to the desired program.
curl -X POST \
"${baseUrl}rest/v1/leads.json?access_token=${AccessToken}" \
-H "Content-Type: application/json" \
-d '
{
"action":"createOrUpdate",
"lookupField":"email",
"input":[
{
"email":"lead#customer.com",
"firstName":"Sergejs",
"lastName":"test"
},
{
"email":"lead#company.com",
"firstName":"Sergejs",
"lastName":"test1"
},
{
"email":"lead#mail.net",
"firstName":"Sergejs",
"lastName":"test2"
}]
}
'
LeadId=$(curl -X GET "${baseUrl}rest/v1/leads.json?access_token=${AccessToken}&filterType=email&filterValues=${leademail}" | jq '.result | .[].id')
curl -X POST "${baseUrl}rest/v1/leads/programs/${NewProgramId}/status.json?access_token=${AccessToken}" \
-H "Content-Type: application/json" \
-d " {
\"status\": \"Registered\",
\"input\": [
{\"id\": ${LeadId} }
]
}
"

Resources