最近在学习Google People API,先看的PHP版的,当GET https://people.googleapis.com/v1/people/me 的时候,想指定获取的内容,比如person.names,person.phoneNumbers,谷歌提供的接口是传入一个数组Query parameters,

Parameter name Type Description
pageToken string The token of the page to be returned.
pageSize number The number of connections to include in the response. Valid values are between 1 and 500, inclusive. Defaults to 100.
sortOrder enum(SortOrder) The order in which the connections should be sorted. Defaults to LAST_MODIFIED_ASCENDING.
syncToken string A sync token, returned by a previous call to people.connections.list. Only resources changed since the sync token was created are returned.
requestMask object(RequestMask) A mask to restrict results to a subset of person fields.

2016-06-25_190016
可以看到最后一个参数requestMask需要传入的值是object,一个对象。
继续点开RequestMask看
2016-06-25_190532
参数includeField要传入的值是string内容
看到这些大家会怎么传入参数呢,于是很自然的想到创建一个RequestMask类,这个RequestMask类有一个参数includeField,将“person.names,person.phoneNumbers”赋值给includeField,最后再将RequestMask传入Query parameters,结果是,我失败了,在网上找答案,没有直接找到,最后无意中还是发现了解决办法
2016-06-25_192504
无语了吧,

$connections = $service->people_connections->listPeopleConnections('people/me', array(
'pageSize' => 500,
'requestMask.includeField' => 'person.names,person.phoneNumbers'
));

想多了,什么传入类不类的,压根都不需要!直接将person.names,person.phoneNumbers赋值给requestMask.includeField即可,无语了吧。直接说string类型不就行了?requestMask.includeField?说好的object呢?难道是string这个object啊


发表评论

电子邮件地址不会被公开。 必填项已用*标注