10-11-2017 03:30 AM
I am new to SAS and want to import data from Google Analytics.
I am following the post (https://blogs.sas.com/content/sasdummy/2017/04/14/using-sas-to-access-google-analytics-apis/) to import Google Analytics data with SAS. The version I use is SAS 9.4
But, I got an error (NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks.) on the code below. Any Advise?
proc http /* put this all on one line! */ url="&oauth2.?client_id=&client_id.%str(&)code=&code_given.%str(&)client_secret=&client_secret.%str(&)redirect_uri=urn:ietf:wg:oauth:2.0:oob%str(&)grant_type=authorization_code%str(&)response_type=token" method="POST" out=token ; run;
10-11-2017 08:46 AM
Are you using SAS Visual Analytics? In VA 7.2 and later you can import data from Google Analytics through the UI:
Hope this helps,
10-11-2017 09:14 PM
Yes, I know I could use the UI. But, it has the limitation of fixed data size (once you've created the lasr table, you cannot add data to that table). What I want to achieve is that to make the lasr table (data source) grow such that my report linked to that data source could have up-to-date data. That's why I use the script to download the data into a staging table and then massage the data to the lasr table.
Am I doing it correctly? Any easier alternative?
10-11-2017 09:14 AM
Assuming you've set the
macro variable as shown in the example that @ChrisHemedinger provided, you could always try to run this line first:
Art, CEO, AnalystFinder.com
10-11-2017 09:39 PM
Thanks a lot. That resolves the error.
However, I receive another error "400 Bad Request". I think it's related to this line. When I ran the URL in a browser, it returns "Not Found". Any ideas?
Here's the full code:
filename token "c:\temp\token.json"; %let code_given =<code-returned-from-step-1> ; %let oauth2=https://www.googleapis.com/oauth2/v4/token; %let client_id=<your-client-id>.apps.googleusercontent.com; %let client_secret=<your-client-secret>; proc http url="&oauth2.?client_id=&client_id.%str(&)code=&code_given.%str(&)client_secret=&client_secret.%str(&)redirect_uri=urn:ietf:wg:oauth:2.0:oob%str(&)grant_type=authorization_code%str(&)response_type=token" method="POST" out=token ; run;