2014-10-27 34 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头固定的问题。