[GoogleAPI][v2][PHP] Google_Client OAuth Token Refresh (getrefreshtoken return null) – 更新Token

情境 PHP SDK文件與範例Code目前版本就是有坑:例如Calendar PHP Google Client OAuth Token就是無法Refresh,調用Method出來就是NULL。 $client->getRefreshToken(); // Output = NULL 解決方法 設定Google_Client時ApprovalPrompt要設為Froce… $client->setApprovalPrompt(‘force’); 修正後的PHP SDK範例: $client = new Google_Client(); $client->setApplicationName(APPLICATION_NAME); $client->setScopes(SCOPES); $client->setAuthConfig(CLIENT_SECRET_PATH); $client->setAccessType(‘offline’); $client->setApprovalPrompt(‘force’); 可以參考2011年文章:Upcoming changes to OAuth 2.0 endpoint

[GoogleAPI][Calendar][PHP] Events: Update DateTime – 日曆更新時間範例 (Google_Service_Calendar_EventDateTime)

緣由 Google Calendar API 目前文件版本在Events Update上竟然沒說明DateTime的相關set方法。 基本文件 Google Calendar API Events: update 以上目前版本並無提及如何Update Start & End DateTime,僅提到使用nested object型態。 PHP範例CODE // First retrieve the event from the API. $event = $service->events->get(‘primary’, ‘eventId’); $event->setSummary(‘Appointment at Somewhere’); // DateTime nested object method $start […]

[GA] Google Analytics – 顯示網域(完整網址)方法

情境 例如跨網域網站共用同一個GA資源,那就有得分出Domain的需求。 解決方法 在GA資源管理篩選器(Filter)中,自訂URL建構方式: 欄位A:選擇Hostname: (.*) 欄位B:選擇Request URI: (.*) 輸出至: 選擇Request URI: $A1$B1 勾選覆蓋輸出欄位(Override Output Field) 用以上取出Hostname+URI合併成新URI後,此篩選器就可以做到在報表上顯示網域(完整網址)。 建議可以另開同一資源來實作此篩選器,以保有兩種格式的資源報表