How can I extract Google analytics data?

조회 수: 3 (최근 30일)
Elham Noorzai
Elham Noorzai 2019년 2월 5일
답변: Rahul 2025년 6월 26일
I have the client_id the client_secret, the authorization code, but how exactly can I extract data from google analytics. In which format do i have to enter startDate or the endDate?
Mein Code bisher
access_token='XXXX';
headerFields = {'Authorization', ['Bearer ', access_token]};
options = weboptions('HeaderFields', headerFields, 'ContentType','json');
webread('https://www.googleapis.com/analytics/v3/data/ga','ids=ga12345',...
'start-date=2018-12-01','end-date=2019-01-31','metrics=ga:sessions', options)
Unfortunately, the in 2016a the HeaderFields cannot be added into weboptions, any workaround?

답변 (1개)

Rahul
Rahul 2025년 6월 26일
I understand that you require to extract the Google analytics data and you might be able to add 'HeaderFields' into weboptions while using MATLAB R2016a. As a workaround, consider using 'urlread2' which is a File Exchange Submission: https://www.mathworks.com/matlabcentral/fileexchange/35693-urlread2
Once downloaded, add it to your MATLAB path and then use it in the following way:
access_token = 'XXXX';
url = ['https://www.googleapis.com/analytics/v3/data/ga?', ...
'ids=ga:12345', ...
'&start-date=2018-12-01', ...
'&end-date=2019-01-31', ...
'&metrics=ga:sessions'];
headers = {'Authorization', ['Bearer ', access_token]};
response = urlread2(url, 'GET', '', headers);
data = loadjson(response);
If MATLAB R2016a would not work with 'jsondecode', consider using 'loadjson' from this MathWorks File Exchange submission:
Thanks.

카테고리

Help CenterFile Exchange에서 Google에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by