Firebase Dynamic Links Analytics API got 403 error

36 Views Asked by At

https://firebase.google.com/docs/reference/dynamic-links/analytics?hl=en

I want to get data from dynamic link that automatically created by app. But it give me 403 error. I searched some other questions from here but cannot solve this problem.

I run code in AWS lambda with node.js. But it also get 403 in my local either.

var { google } = require("googleapis"); const axios = require("axios"); 
var serviceAccount = require("./json.json"); //get from firebase project setting

async function fetchData() { // Specify the required scope. var scopes = ["https://www.googleapis.com/auth/firebase"];

// Authenticate a JWT client with the service account.
var jwtClient = new google.auth.JWT(
    serviceAccount.client_email,
    null,
    serviceAccount.private_key,
    scopes
);

// Use the JWT client to generate an access token.
const token = await jwtClient.authorize();
const ACCESS_TOKEN = token.access_token;

const url = "https://LINK_URL";
const encodedUrl = encodeURIComponent(url);

// https://tikkle.lifoli.co.kr/CQm1
const API_URL =
    "https://firebasedynamiclinks.googleapis.com/v1/" +
    encodedUrl +
    "/linkStats?durationDays=30";

const response = await axios.get(API_URL, {
    headers: {
        Authorization: "Bearer " + ACCESS_TOKEN,
    },
});

// Handle the response here
console.log("Response:", response.data);
return response;
}

fetchData();

I got serviceAccount from "google-service.json" and I am editor of firebase project. Plus, I run that code with "google-service.json" of the owner of the firebase project but it gives me 403 too.

    {
"error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
        "domain": "googleapis.com",
        "metadata": {
          "method": "google.firebase.dynamiclinks.v1.DynamicLinksService.GetShortDynamicLinkStats",
          "service": "firebasedynamiclinks.googleapis.com"
        }
      }
    ]
  }
}
0

There are 0 best solutions below