Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobieranie danych z API google analytics
chomikiki
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 1
Dołączył: 16.09.2016
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Cześć,
Niestety przeszukując zasoby internetu nie mogę znaleźć tutoriala jak pobrać dane na swoją stronę. Jak już znalazłam jakieś kody to nie działają, albo ja ich nie potrafię użyć (to drugie bardziej prawdopodobne). Doszłam do przycisku logowania, ale tez wyskakuje błąd i nie bardzo wiem co dalej. Zna ktoś może jakieś tutoriale, albo powie co po kolei powinnam zrobić? Jestem wzrokowcem i najszybciej kumam o co chodzi jak widzę przykład. Niestety jedyne przykłady jakie znalazlam dotyczą umieszczenia wtyczki do pobierania danych przez google a nie pobierania danych Z google (IMG:style_emoticons/default/sad.gif) Bardzo proszę o pomoc

Ten post edytował chomikiki 21.09.2016, 11:08:37
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
chomikiki
post
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 1
Dołączył: 16.09.2016
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


po wklejeniu:

error_reporting(E_ALL);
ini_set('display_errors','1');

na początku strony pokazuje:
"Fatal error: Uncaught exception 'Google_Exception' with message 'Invalid client secret JSON file.' in /[...]/google-api-php-client/src/Google/Client.php:171 Stack trace: #0 /[...]/view/admin/HelloAnalytics.php(47): Google_Client->setAuthConfig('/home/admin/web...') #1 /[...]/view/admin/HelloAnalytics.php(30): initializeAnalytics() #2 {main} thrown in /[...]/google-api-php-client/src/Google/Client.php on line 171"

Ponieważ nie mogę ujawnić strony pod [...] kryje się link do głównego folderu.

view\admin\HelloAnalytics.php
[30] $analytics = initializeAnalytics();

[35-52]
  1. function initializeAnalytics()
  2. {
  3. // Creates and returns the Analytics Reporting service object.
  4.  
  5. // Use the developers console and download your service account
  6. // credentials in JSON format. Place them in this directory or
  7. // change the key file location if necessary.
  8. $KEY_FILE_LOCATION = __DIR__ . 'view\admin\client_secret.json';
  9.  
  10. // Create and configure a new client object.
  11. $client = new Google_Client();
  12. $client->setApplicationName("Hello Analytics Reporting");
  13. $client->setAuthConfig($KEY_FILE_LOCATION); // <- [47]
  14. $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
  15. $analytics = new Google_Service_Analytics($client);
  16.  
  17. return $analytics;
  18. }


google-api-php-client\src\Google\Client.php
[166-178]
  1. public function setAuthConfig($json)
  2. {
  3. $data = json_decode($json);
  4. $key = isset($data->installed) ? 'installed' : 'web';
  5. if (!isset($data->$key)) {
  6. throw new Google_Exception("Invalid client secret JSON file.");
  7. }
  8. $this->setClientId($data->$key->client_id);
  9. $this->setClientSecret($data->$key->client_secret);
  10. if (isset($data->$key->redirect_uris)) {
  11. $this->setRedirectUri($data->$key->redirect_uris[0]);
  12. }
  13. }


nawet po ponownym pobraniu pliku (niby właściwego dla utworzonego projektu w "console.developers.google.com/apis/credentials") nie działa (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 07:17