背景故事:
从Provisioning API迁移到Admin SDK Directory API。使用Perl。 我可以成功获取Bearer令牌,我可以使用该令牌获取整个域的单独用户资源和用户资源列表。一切正常。我确保我在令牌请求中使用了适当的范围(https://www.googleapis.com/auth/admin.directory.user)。
问题: 更新用户的呼叫返回200 OK(预期),但没有接收到更改。
使用LWP PUT更新请求。这是请求返回后LWP对象的转储。您可以看到我收到200 OK响应和User Resource对象作为响应的一部分。您还可以看到返回的用户资源未反映我在请求中发送的更改。我已在管理控制台中确认该域未发现更改。
任何帮助都将不胜感激。
'_content' => '{
"kind": "admin#directory#user",
"id": "somenumber",
"etag": "\\"etag\\"",
"primaryEmail": "user@googletestdomain",
"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": "user@googletestdomain",
"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/user@googletestdomain'
'_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/user@googletestdomain';
my $ua = LWP::UserAgent->new(timeout => 30);
my $res = $ua->put($url,
'Authorization' => 'Bearer '.$auth_token,
'Content' => $ur,
);
答案 0 :(得分:2)
将Content-Type
请求中的PUT
标题设置为application/json
解决了问题。