如上篇,只能拿到基本的資料,如姓名、email、大頭貼等等。
想取得更詳細的資料,如年齡、性別、電話等等,則需透過Google People API來取得,PHP的話有Google APIs Client Library for PHP可以使用。
以Laravel為例:先安裝google api client:
$ composer require google/apiclient:"^2.7"
續上篇,將程式碼改成這樣:
因為已經拿到access token了,就可以直接用這個token來取得user資料。
最終print出來的結果如下:

值得一提的是,像性別、生日這種敏感資料,必須要user有同意公開才拿的到,以gender為例,這邊拿的到是因為我的測試帳號有設定公開。

本筆記參考:
1. https://blog.johnsonlu.org/using-oauth-2-0-to-access-google-apis-with-google-api-php-client/
2. https://stackoverflow.com/questions/52380440/how-to-get-data-form-google-service-peopleservice
3. https://developers.google.com/people/quickstart/php
4. https://github.com/googleapis/google-api-php-client