我尝试获取“缩短的”firebase动态链接的动态链接信息(点击统计信息)。
这是我到目前为止的来源:
$client = new Google_Client();
$client->setAuthConfig(DIR_APP . '/lib/Google/client_credentials.json');
$client->addScope(Google_Service_FirebaseDynamicLinks::FIREBASE);
$service = new Google_Service_FirebaseDynamicLinks($client);
$response = $service->v1->getLinkStats($short_url);
这给了我以下错误:
cURL error 7: (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
---------------------------------
CURLE_COULDNT_CONNECT (7)
Failed to connect() to host or proxy.
$ service-> rootUrl出于某些原因“https://firebasedynamiclinks-ipv6.googleapis.com/”,但即使我将其更改为“https://firebasedynamiclinks.googleapis.com/”(如“https://firebase.google.com/docs/reference/dynamic-links/analytics”中的含义)错误仍然是一样的。
我觉得我错过了一些非常简单的事情,有人能指出我正确的方向吗?
答案 0 :(得分:1)
找到它,不是直接回答我原来的问题,而是解决问题本身。
$short_url = "https://abc.app.goo.gl/12345abc";
$client = new Google_Client();
$client->addScope(Google_Service_FirebaseDynamicLinks::FIREBASE);
$client->setAuthConfig('/path/to/credentials.json');
$client->fetchAccessTokenWithAssertion();
$authorization = 'Authorization: Bearer '.$client->getAccessToken()['access_token'];
$url = "https://firebasedynamiclinks.googleapis.com/v1/".urlencode($short_url)."/linkStats?durationDays=7";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_exec($ch);
print_r($ret);
打印出来:
{
"linkEventStats": [
{
"count": "4",
"event": "CLICK",
"platform": "OTHER"
},
{
"count": "4",
"event": "REDIRECT",
"platform": "OTHER"
}
]
}