Hi,
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;
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,
Sam
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?
Assuming you've set the
oauth2
macro variable as shown in the example that @ChrisHemedinger provided, you could always try to run this line first:
options NOQUOTELENMAX;
Art, CEO, AnalystFinder.com
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?
%let oauth2=https://www.googleapis.com/oauth2/v4/token;
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.