Google API uses client login login authorization

Source: Internet
Author: User
Tags oauth php example stack trace account security

Google Analytics is used today to get data from Google, so you have to use Google's login authorization.

Google's service certification system includes a variety of authentication authorizations, such as authsub authorized Authentication Service, OAuth authorized authentication Service and Clientlogin authorized authentication Service. Specifically, we can refer to:

http://blog.csdn.net/hereweare2009/article/details/4002537

http://blog.zhourunsheng.com/2011/07/%E8%84%9A%E6%9C%AC%E6%96%B9%E5%BC%8F%E8%8E%B7%E5%8F%96google-clientlogin-auth-token/

Today, the focus is on Google clientlogin Licensing certification.

In fact, certification is not a hassle, using curl easy to achieve. Here is a simple code:

$data=Array(            ' AccountType ' + ' GOOGLE ', ' Email ' and ' = '$email, ' Passwd ' =$password, ' service ' = ' analytics ',//Google a series of API shorthand, can be found on Google, can be replaced by the service you want to shorthand' Source ' = ' test-oauth-1.0 ',//give your own application a name        ); $ch=Curl_init (); curl_setopt ($ch, Curlopt_url, "Https://www.google.com/accounts/ClientLogin"); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_post,true); curl_setopt ($ch, Curlopt_postfields,$data); curl_setopt ($ch, Curlopt_ssl_verifypeer, 0); $output= Curl_exec ($ch); $info= Curl_getinfo ($ch);

The above code is just a simple implementation, you can find it very simple, in fact, the official provided a PHP operation Class Gapi (the last one is also roughly said), for the Google Analytics data to get the powerful, very recommended to use. Cloud Disk Address: Http://pan.baidu.com/s/1kTIEIov, I only use the inside of the gapi.class.php & example.report.php.

These are not difficult, generally can be solved. Today it is important to emphasize that in the process of use, I have encountered such a problem:

[[email protected] GA]#PHP example.report.phpFatal Error: uncaughtException' Exception ' with message 'gapi:failed to authenticate user. Error: "error=badauthenticationurl=https://www.google.com/accounts/continuesignin?sarp=1&scc=1&plt= akgnsbufmhdsjlfjdlsjooxtjxexc4le_gs-dxfmftjtvp-c2nglore4x9clckvrrdtxugccdk-cg18gik_- Evoze8anhsdfdshjfh46ygvrfxanepm8zo-mpjcy8_cje-0368ukkfkpb0nexpkddidsvsova11ks_ zkhyaw2n9zl2pphbt53wfsdhkjhduigcvsk--5r79hfdsjkfvxb-ry-7yji3d8m1mpdhxuiged5t11gvesaqwhaijcinfo= Webloginrequired "' In/root/ga/gapi.class. php:418Stack Trace:#0/root/ga/gapi.class.php (+): Gapi->authenticateuser (' [email protected] ', ' xxxxxxx ')#1/root/ga/example.report.php (9): gapi->__construct (' [email protected] ', ' xxxxx ')#2 {main}Thrown In/root/ga/gapi.class. PHP On line 418

It is estimated that there is a great possibility for all of us to meet, and I once doubted whether it was the reason for the wall GFW (which has been returning 403, thus excluding the GFW reason). With Google's help, we finally found the answer (see Http://stackoverflow.com/questions/15742352/google-api-login) because of Google's account security settings, To allow the app to be accessed.

The solution is as follows:

1, click Https://accounts.google.com/DisplayUnlockCaptcha click on the page to continue, and then continue the program, whether there are problems, there are problems, and then continue the second step;

2. Click Https://www.google.com/settings/security/lesssecureapps to see if "insecure apps" is enabled, select Enable, and click Done.

This should solve the problem.

Google API uses client login login authorization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.