Reputation: 477
When trying to query Google Firebase dynamic link stats I am getting an empty object.
I've got 5 dynamic links in the firebase console which were created via the console. Using the following code I am able to get a token. I used the GCP->IAM->Service Accounts to create a new account and pull down the JSON file. I've ensured the project_id matches the one in firebase.
link = "my_dynamic_link_short_name"
scopes = ["https://www.googleapis.com/auth/firebase"]
credentials = service_account.Credentials.from_service_account_file("key.json", scopes=scopes)
url_base = "https://firebasedynamiclinks.googleapis.com/v1/SHORT_DYNAMIC_LINK/linkStats?durationDays=1"
encoded_link = urllib.parse.quote(link, safe='')
url = url_base.replace('SHORT_DYNAMIC_LINK', encoded_link)
request = Request()
credentials.refresh(request)
access_token = credentials.token
HEADER = {"Authorization": "Bearer " + access_token}
response = requests.get(url, headers=HEADER)
print(response.json())
Both of the above requests return a 200 but no data returned.
The GCP service account I am using has the following roles:
I've given it full owner to test and it didn't resolve issue.
Upvotes: 1
Views: 989
Reputation: 10519
FDL Analytics REST API returns an empty object {}
if the short link doesn't have analytics data on the specified date range. If you have existing short links in the FDL dashboard that has click data, you can use it to validate if the response from the API matches the data displayed on the dashboard.
If you're still having issues, I suggest filing a ticket https://firebase.google.com/support
Edit: To add, Firebase Dynamic Links click data are aggregated daily and should be updated the next day. For newly created links, give it a day or two for the click data to be updated. This applies on both click data from the API and the one displayed on the dashboard.
Upvotes: 2