关于perl:调用更新用户返回200 OK,但不更新用户

Calls to update a user return 200 OK but do not update user

背景故事:

从Provisioning API迁移到Admin SDK Directory API。使用Perl。
我可以成功获取Bearer令牌,并且可以使用该令牌获取整个域的单个用户资源和用户资源列表。这一切都很好。我确保我在令牌请求(https://www.googleapis.com/auth/admin.directory.user)中使用了适当的范围。

问题:
更新用户的电话返回200 OK(预期),但未接收到更改。

使用LWP放置更新请求。这是请求返回后LWP对象的转储。您会看到我收到200 OK响应和一个User Resource对象作为响应的一部分。您还可以看到返回的用户资源不反映我在请求中发送的更改。我已经在域的管理控制台中确认未接受更改。

任何帮助将不胜感激。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'_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

以下是所用代码的示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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,
);


PUT请求中的Content-Type标头设置为application/json可解决此问题。