我尝试获取“缩短的”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->根but是“https://firebasedynamiclinks-ipv6.googleapis.com/”,但即使我将其改为"https://firebasedynamiclinks.googleapis.com/“(就像在”https://firebase.google.com/docs/reference/dynamic-links/analytics“处所指的那样),错误仍然是一样的。
我感觉我错过了一些非常简单的东西,谁能给我指个正确的方向?
发布于 2018-06-13 15:05:05
找到了,不是我最初问题的直接答案,而是问题本身的解决方案。
$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"
}
]
}https://stackoverflow.com/questions/50813640
复制相似问题