如何使用 PHP 使用 google API 获取用户“contactid”

2023-12-09

我正在尝试使用 google API 3.0 获取用户联系人以及所有用户详细信息。 我能够获得包含用户详细信息的 JSON 响应。

$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;

结果是

   [entry] => Array
            (
                [0] => Array
                    (
                        [id] => Array
                            (
                                [$t] => http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
                            )

                        [gd$etag] => "RXc7fTVSLit7I2A9XRZaEkoLRAw."
                        [updated] => Array
                            (
                                [$t] => 2014-08-29T00:16:24.905Z
                            )

                        [app$edited] => Array
                            (
                                [xmlns$app] => http://www.w3.org/2007/app
                                [$t] => 2014-08-29T00:16:24.905Z
                            )

                        [category] => Array
                            (
                                [0] => Array
                                    (
                                        [scheme] => http://schemas.google.com/g/2005#kind
                                        [term] => http://schemas.google.com/contact/2008#contact
                                    )

                            )

                        [title] => Array
                            (
                                [$t] => abc
                            )

                        [link] => Array
                            (
                                [0] => Array
                                    (
                                        [rel] => http://schemas.google.com/contacts/2008/rel#photo
                                        [type] => image
                                        [href] => https://www.google.com/m8/feeds/photos/media/sachdfwdfd%40gmail.com/1?v=3.0
                                        [gd$etag] => "VWVIH3oyWit7I2B0UBRURzwNBWM8ODs8cSk."
                                    )

                                [1] => Array
                                    (
                                        [rel] => self
                                        [type] => application/atom+xml
                                        [href] => https://www.google.com/m8/feeds/contacts/sachitdff%40gmail.com/full/1?v=3.0
                                    )

                                [2] => Array
                                    (
                                        [rel] => edit
                                        [type] => application/atom+xml
                                        [href] => https://www.google.com/m8/feeds/contacts/sachidtfd%40gmail.com/full/1?v=3.0
                                    )

                            )

                        [gd$name] => Array
                            (
                                [gd$fullName] => Array
                                    (
                                        [$t] => abc xyz 
                                    )

                                [gd$givenName] => Array
                                    (
                                        [$t] => abc
                                    )

                                [gd$familyName] => Array
                                    (
                                        [$t] => xyz
                                    )

                            )

                        [gd$email] => Array
                            (
                                [0] => Array
                                    (
                                        [address] => [email protected]
                                        [primary] => true
                                        [rel] => http://schemas.google.com/g/2005#other
                                    )

                            )

                        [gContact$website] => Array
                            (
                                [0] => Array
                                    (
                                        [href] => http://www.google.com/profiles/104048264070958665151
                                        [rel] => profile
                                    )

                            )

                        [gContact$groupMembershipInfo] => Array
                            (
                                [0] => Array
                                    (
                                        [deleted] => false
                                        [href] => http://www.google.com/m8/feeds/groups/sachitaware

                            )

                    )

但在这里我不明白联系图片用户的。文档说我需要一个联系人号码用于获取照片,但我在上面的响应中没有获取联系人 ID。如何获取用户的联系人 ID 以及随后的联系人照片?

我已经使用 oauth 2.0 授权了该应用程序,除了图像之外,我还获得了联系人的大部分详细信息。

EDIT:我试过this文档中的方式并且它有效,但它返回二进制图像而不是图片网址我必须发送另一个请求才能获取图像。

 $url1   ='https://www.google.com/m8/feeds/photos/media/{useremail}/13444?       v=3.0&oauth_token='.$accesstoken;
 $xmlresponse1 =  curl($url1);

显示图像:

 <img src="data:image/*;base64,<?php echo base64_encode($xmlresponse1); ?> />

我无法获取像 facebook 这样返回的联系人图片 URL 吗?


根据文档,contactIidAPI返回的联系人条目URL中返回:

http://www.google.com/m8/feeds/contacts/<userEmail>/base/<contactId>

所以,给出你的样本:

http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1

我们有这些价值观:

userEmail: [email protected]
contactId: 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 PHP 使用 google API 获取用户“contactid” 的相关文章

随机推荐