バックストーリー:
Provisioning API から Admin SDK Directory API への移行。パールを使用。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,
);