2015-04-17 141 views
2

我試圖發佈一些活動到用戶個人資料在他們的谷歌+。谷歌api的時刻錯誤代碼400 php

我一直在尋找關於時刻問題的所有文章,但仍然無法解決我的問題。下面是我的代碼

$requestVisibleActions = array(
    'http://schemas.google.com/AddActivity'); 
    $client = new Google_Client(); 
    $client->setApplicationName("PHP Google OAuth Login Example"); 
    $client->setClientId($client_id); 
    $client->setClientSecret($client_secret); 
    $client->setRedirectUri($redirect_uri); 
    $client->setDeveloperKey($simple_api_key); 
    $client->addScope("https://www.googleapis.com/auth/plus.login"); 
    $client->addScope("https://www.googleapis.com/auth/plus.me"); 
    $client->addScope("https://www.googleapis.com/auth/userinfo.email");  
    $client->setRequestVisibleActions($requestVisibleActions); 

    $plus = new Google_Service_Plus($client); 

    // Add Access Token to Session 
    if (isset($_GET['code'])) { 
    $client->authenticate($_GET['code']); 
    $_SESSION['access_token'] = $client->getAccessToken(); 
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); 
    } 

    // Set Access Token to make Request 
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 
    $client->setAccessToken($_SESSION['access_token']); 
    } 

    // Post moment from mysite 
    if ($client->getAccessToken()) { 
    $moment = new Google_Service_Plus_Moment(); 
    $moment->setType('http://schemas.google.com/AddActivity'); 
    $itemScope = new Google_Service_Plus_ItemScope(); 
    $itemScope->setUrl('http://developers.google.com/+/web/snippet/examples/thing'); 
    $moment->setTarget($itemScope); 
    $momentResult = $plus->moments->insert('me', 'vault',$moment); 
    $_SESSION['access_token'] = $client->getAccessToken(); 
    } else {  
    $authUrl = $client->createAuthUrl(); 
    redirect($authUrl); 
    } 

,但我得到一個谷歌的異常錯誤

類型:Google_Service_Exception

Message: Error calling POST 
https://www.googleapis.com/plus/v1/people/me/moments/vault?key=xxxxxxx: 
(400) Unable to fetch metadata. 
Filename: /home2/mysite/public_html/application/libraries/google-api-php-client-master/src/Google/Http/REST.php 

當我試圖訪問帖子的網址我得到這個。

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "Login Required", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Login Required" 
} 
} 

我真的不知道我的錯在哪裏。請幫助我

+0

好心幫助任何人請:(一直在尋找這整個8小時的我的轉變 –

回答

1

Moments: insert記錄表示用戶操作的時刻,例如在博客上進行購買或評論。寫作時刻包括指定類型,這是一種瞬間類型,併發布該類型的時刻必填字段。

Moments描述用戶在您的應用中進行的活動。

Momemt類型相同App Activity Types它們分別是:

的addAction ,BuyAction,CheckInAction,CommentAction,CreateAction,DiscoverAction,ListenAction,ReserveAction,ReviewAction,WantAction

一會兒是NOT發佈到用戶Google+信息流。這是不是可能在Google+中發佈一些活動到用戶個人資料。

+0

@DalmTo嗨,我明白那一刻不是發佈在谷歌+流我只是想從我的網站有一個活動日誌。不能得到它的工作 –