2014-10-27 52 views
1

背景故事:呼叫更新用戶返回200確定但不更新用戶

從Provisioning API遷移到Admin SDK Directory API。使用Perl。 我可以成功獲取持票人令牌,並且可以使用令牌獲取整個域的單個用戶資源和用戶資源列表。這一切工作正常。我已確保我在令牌請求中使用了適當的範圍(https://www.googleapis.com/auth/admin.directory.user)。

問題: 更新用戶的調用正在返回200 OK(預期),但未發現更改。

使用LWP來放置更新請求。這是請求返回後LWP對象的轉儲。你可以看到我得到了200 OK響應和一個用戶資源對象作爲響應的一部分。您還可以看到返回的用戶資源不反映我在請求中發送的更改。我已在域的管理控制檯中確認沒有找到更改。

任何幫助,將不勝感激。

'_content' => '{ 
"kind": "admin#directory#user", 
"id": "somenumber", 
"etag": "\\"etag\\"", 
"primaryEmail": "[email protected]", 
"name": { 
    "givenName": "user", 
    "familyName": "name", 
    "fullName": "user name" 
}, 
"isAdmin": false, 
"isDelegatedAdmin": false, 
"lastLoginTime": "2014-10-02T17:20:02.000Z", 
"creationTime": "2010-01-04T22:27:44.000Z", 
"agreedToTerms": true, 
"suspended": false, 
"changePasswordAtNextLogin": false, 
"ipWhitelisted": false, 
"emails": [ 
    { 
    "address": "[email protected]", 
    "primary": true 
    }, 
], 
"customerId": "C01id", 
"orgUnitPath": "/", 
"isMailboxSetup": true, 
"includeInGlobalAddressList": true 
} 
' 
'_headers' => HTTP::Headers=HASH(0x2031048) 
    '::std_case' => HASH(0x2031240) 
     'alternate-protocol' => 'Alternate-Protocol' 
     'client-date' => 'Client-Date' 
     'client-peer' => 'Client-Peer' 
     'client-response-num' => 'Client-Response-Num' 
     'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer' 
     'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject' 
     'client-ssl-cipher' => 'Client-SSL-Cipher' 
     'client-ssl-socket-class' => 'Client-SSL-Socket-Class' 
     'x-content-type-options' => 'X-Content-Type-Options' 
     'x-frame-options' => 'X-Frame-Options' 
     'x-xss-protection' => 'X-XSS-Protection' 
    'alternate-protocol' => '443:quic,p=0.01' 
    'cache-control' => 'no-cache, no-store, max-age=0, must-revalidate' 
    'client-date' => 'Mon, 27 Oct 2014 17:48:14 GMT' 
    'client-peer' => '173.194.79.95:443' 
    'client-response-num' => 1 
    'client-ssl-cert-issuer' => '/C=US/O=Google Inc/CN=Google Internet Authority G2' 
    'client-ssl-cert-subject' => '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com' 
    'client-ssl-cipher' => 'ECDHE-RSA-AES128-GCM-SHA256' 
    'client-ssl-socket-class' => 'IO::Socket::SSL' 
    'connection' => 'close' 
    'content-type' => 'application/json; charset=UTF-8' 
    'date' => 'Mon, 27 Oct 2014 17:48:14 GMT' 
    'etag' => '"etag"' 
    'expires' => 'Fri, 01 Jan 1990 00:00:00 GMT' 
    'pragma' => 'no-cache' 
    'server' => 'GSE' 
    'vary' => ARRAY(0x20311b0) 
     0 'Origin' 
     1 'Referer' 
     2 'X-Origin' 
    'x-content-type-options' => 'nosniff' 
    'x-frame-options' => 'SAMEORIGIN' 
    'x-xss-protection' => '1; mode=block' 
'_msg' => 'OK' 
'_protocol' => 'HTTP/1.1' 
'_rc' => 200 
'_request' => HTTP::Request=HASH(0x1f5dc90) 
    '_content' => '{"name":{"givenName":"BBB","familyName":"BBB"}}' 
    '_headers' => HTTP::Headers=HASH(0x224fa08) 
     '::std_case' => HASH(0x1f28c90) 
     'if-ssl-cert-subject' => 'If-SSL-Cert-Subject' 
     'authorization' => 'Bearer mytokenhere' 
     'content-length' => 47 
     'user-agent' => 'libwww-perl/6.05' 
    '_method' => 'PUT' 
    '_uri' => URI::https=SCALAR(0x1cbc8b8) 
     -> 'https://www.googleapis.com/admin/directory/v1/users/[email protected]' 
    '_uri_canonical' => URI::https=SCALAR(0x1cbc8b8) 
     -> REUSED_ADDRESS 

下面是所使用的代碼的一個示例:

#!/usr/bin/perl -w 

use JSON; 
use LWP::UserAgent; 

my $auth_token = 'myauthtoken'; 

my $changes = { 
    'name' => { 
    'givenName' => 'BBB', 
    }, 
}; 

my $json = new JSON; 
my $ur = $json->encode($changes,{utf8 => 1}); 

my $url = 'https://www.googleapis.com/admin/directory/v1/users/[email protected]'; 
my $ua = LWP::UserAgent->new(timeout => 30); 
my $res = $ua->put($url, 
    'Authorization' => 'Bearer '.$auth_token, 
    'Content' => $ur, 
); 
+1

我在請求標頭中看不到「Content-Type:application/json」...也許嘗試明確設置它。這也有助於查看您用於生成和發送請求的代碼,而不僅僅是響應的轉儲。 – ThisSuitIsBlackNot 2014-10-27 19:21:46

+0

在運行腳本之前,您是否在API Explorer中嘗試[測試您的請求](https://developers.google.com/admin-sdk/directory/v1/reference/users/update#try-it)?這將是一個很好的理智檢查。 – ThisSuitIsBlackNot 2014-10-27 19:23:08

+0

我曾嘗試在API Explorer中進行測試,並且該更改在此處正常工作。 – 2014-10-27 20:13:12

回答

2

PUT請求application/json設置Content-Type頭固定的問題。