How to get a list of views (profiles) in google analytics api v4 - google-analytics-api

I'm trying to upgrade my script from using version 3 of the google analytics API to version 4.
In version 3, I could get listings of accounts, properties, and views from the api (see API reference for version 3). However, the API reference for version 4 does not seem to show the same thing.
How do I get those listings now?

TLDR: You get the view listings the same way you always have.
The Analytics Reporting API V4 is a stand alone API for querying an Analytics View for data. There is not V4 management API, only the Analytics Management API V3. The two APIs are designed to be used together.
To load both the V3 and V4 libraries in Python:
from apiclient.discovery import build;
analytics = build('analytics', 'v3', http=http)
analyticsReporting = build('analyticsreporting','v4', http=http)
The best way to list all the views of a user is to call accountsummaries.list() -- See the method reference docs for details.
account_summaries = analytics.management().accountSummaries().list().execute()
Parse the response to get the viewId of interest, and call the V4 API:
response = analyticsreporting.reports().batchGet(
body={
"reportRequests":[
{
"viewId": viewId,
"dateRanges":[
{
"startDate":"2015-06-15",
"endDate":"2015-06-30"
}],
"metrics":[
{
"expression":"ga:sessions"
}],
"dimensions": [
{
"name":"ga:browser"
}]
}]
}
).execute()

Related

Facebook app_insights metric keys returning 0 data

Is anyone having trouble getting Facebook metric data from the app_insights edge? Hoping to get a sanity check about the Facebook graph API. In the past we could use story_clicks, story_publishes and story_impressions to get data about our facebook app. For example we would use the request of
https://graph.facebook.com/v5.0/APP_ID/app_insights/story_publishes
to return data about our facebook application. We know the application is making posts, and the request doesn't return an error, but all we get are data points that look like this:
{
"data": [
{
"time": "2019-12-02T08:00:00+0000",
"value": "0"
}
]
}
The app_insights endpoint is still listed in the 5.0 graph api documentation, and nothing related to this seems to be listed in the changelog

How to set the tracking_specs when creating Facebook ads?

I am trying to create an ad using the Facebook Marketing API. In order to create an ad inside a conversion based campaign, I am required to set proper tracking_specs values.
Querying existing ads (on other similar campaigns) I see the tracking spec is generally defined as follows:
"tracking_specs": [
{
"action.type": ["offsite_conversion"],
"fb_pixel": [<pixel ID>]
},
{
"action.type": ["post_engagement"],
"page": [<page ID>],
"post": [<post ID>]
},
{
"action.type": ["link_click"],
"post": [<post ID>],
"post.wall": [<post.wall ID>]
}
]
How do I find the required tracking_specs values? More specifically, how do I find the post ID and the post.wall ID accordingly for post_engagement and link_click action types?
I managed to figure it out on my own. When creating a new ad, in a conversion typed campaign, an ad data object that includes tracking specs should be provided. These tracking specs should include some reference to a Facebook pixel.
"tracking_specs": [
{
"action.type": ["offsite_conversion"],
"fb_pixel": [<pixel ID>]
},
]
The pixels data can be obtained manually via the Facebook Business Manager or via the Facebook Marketing APIs:
GET /v2.10/{ad-account-id}/adspixels HTTP/1.1
Host: graph.facebook.com
Read more in https://developers.facebook.com/docs/marketing-api/reference/ad-account/adspixels/
Regarding the post and post.wall IDs - these are automatically added by Facebook when the ad is created. So there is no need to include theses when creating the ad.
For anyone searching for an answer in 2023. asaf's answer is totally correct BUT you also need to wait until Meta Business Manager processes your campaign in order to see tracking_specs into the API and in the Business Manager itself.

Facebook api graph v2.4 get simple data

it is possible to get group post with graph v2.4 ?
cause i can't get anything with it , can't get post infos , can't comment .. nothing
in the other versions everything works great
and unfortunately the access token generated from the apps can only work with v2.4
i'm doing a cron job for that i have to use the app to refresh access token so i'm forced to use 2.4 , any solution for this ?
here's what i tried to do :
https://developers.facebook.com/tools/explorer/?method=GET&path=id_of_my_group_post&version=v2.4
Getting this error :
{
"error": {
"message": "No node specified",
"type": "GraphMethodException",
"code": 100
}
}
if i changed : &version=v2.4 to any other version it will work fine.
By the looks of your code snippet you are using Facebook Query Language (FQL). However, you need to be aware that this framework is NOT supported in Graph API v2.4. In fact, Facebook announced it will be only supported up to version 2.0. See quote below from the Reference Page...
Version 2.0 of the Facebook Platform API is the last version where FQL will be available. Versions after 2.0 will not support FQL. Please migrate your applications to use Graph API instead of FQL. Please see our changelog for current version information.

Creating Facebook Custom Audience from graph api give Error (#100) Pixel ID Required: pixel_id is required to create WCA

I want to create Custom Audience for Facebook ads using graph api but it gives me error :
" (#100) Pixel ID Required: pixel_id is required to create WCA "
I am using graph api v2.3 in python.
My code for creating Facebook Custom Audience is:
audience = CustomAudience(parent_id= account_id)
audience[CustomAudience.Field.name]= 'DemoAudience'
audience[CustomAudience.Field.description]= "Audience Descrip"
audience[CustomAudience.Field.subtype] = 'WEBSITE'
audience[CustomAudience.Field.retention_days] ='15'
audience[CustomAudience.Field.rule] = { "url": { "i_contains": "shoes" } }
new_custom_audience = audience.remote_create()
It seems that this is a bug in the documentation. You need to create a pixel first and then provide that using the "pixel_id" field. See https://developers.facebook.com/docs/marketing-api/custom-audience-website/v2.3 for more information about that pixel.
I've created a bug report for this, to indicate that the documentation is incorrect. The url of that report: https://developers.facebook.com/bugs/1390317697957586/. Feel free to subscribe to keep updated.
Had the same problem today, though I was using direct queries to the graph api (i.e. not using their sdk).
Seems to be a bug in API v2.3. When I switched to 2.2 the error was gone and my audience was created successfully.
I just had a quick look into the python API. Seems like there's no option to overwrite the default api version. But editing line 134 in facebookads/api.py should do the trick.

What's the best way to get the main currency for a company using the QBO API?

Using the QBO API how do I determine what currency the company is using in their QuickBooks file or overall as a company? Thanks!
Okay, chalk this up to not reading a little more into the docs, you can easily find this under the Company Preferences under "HomeCurrency", using the QBO api v3 you can find it under this url:
https://qb.sbfinance.intuit.com/v3/company/realm_id_goes_here/preferences
And should see some json like this:
...
"CurrencyPrefs": {
"MultiCurrencyEnabled": false,
"HomeCurrency": {
"value": "USD"
}
},
....