Google api 如何检查谷歌用户';s图像是默认的还是上载的?

Google api 如何检查谷歌用户';s图像是默认的还是上载的?,google-api,google-plus,Google Api,Google Plus,如何检查用户的个人资料图片是默认图片还是上传到谷歌 注意:当您从API获取用户详细信息时 包括图像对象中的isDefault值。例如,如果你在+Google上尝试,你会得到 "image": { "url": "https://lh4.googleusercontent.com/-v0soe-ievYE/AAAAAAAAAAI/AAAAAAACyas/yR1_yhwBcBA/photo.jpg?sz=50", "isDefault": false } people.get不再将

如何检查用户的个人资料图片是默认图片还是上传到谷歌

注意:当您从API获取用户详细信息时

包括图像对象中的
isDefault
值。例如,如果你在
+Google
上尝试,你会得到

"image": {
    "url": "https://lh4.googleusercontent.com/-v0soe-ievYE/AAAAAAAAAAI/AAAAAAACyas/yR1_yhwBcBA/photo.jpg?sz=50",
    "isDefault": false
}

people.get不再将isDefault作为属性。
所有默认配置文件图片都有以下URL:

https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg

您只需将配置文件图片的字符串相等性与给定图片进行比较。

在ruby中,使用designe和omniauth-google-oauth2

在你的设计中

config.omniauth :google_oauth2 (Other options....), skip_image_info: false
然后在user.rb/其他位置:

def self.parse_auth_image(auth)
  if auth.provider == "google_oauth2"
    return nil if auth.dig("extra", "raw_info", "image", "isDefault")
  end
  auth.info.image
end

详细介绍此操作的最佳方法:

require 'open-uri'
默认图像:

default = "https://lh3.googleusercontent.com/-
XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg"
要检查的图像:

image_to_check = "https://lh3.googleusercontent.com/-
uh4wK1JDtCI/AAAAAAAAAAI/AAAAAAAAAAA/huieBSbV4zg/s64-
c/100695019739939096169.jpg"
比较检查

blob_for_default_image = open(default).read

blob_for_image_to_check = open(image_to_check).read 
然后比较两个图像斑点:

blob_for_default_image == blob_for_image_to_check 

更新2020年的答案:现在可以通过向
人员发送请求来获取用户的个人资料图片。获取带有
照片的
API作为
人员配置文件
进行请求

您将返回一个图像数组,无论何时出现
default:true
,这意味着它是一个默认(非用户设置)图像:

示例(如果您正在使用OAuth):

得到

样本响应(带个人资料图片)

样本响应(仅限默认值)


如果您使用的是PHP,它相当简单,只需使用以下代码

$profile_img_end = explode("/", $userData['picture']); // Exploding the URL and Dividing it into several terms

if (end($profile_img_end) === "photo.jpg") { // Now Simply Check if last part of array is equal to "photo.jpg" which is common in all default images
    $profile_img = null; // If it's default then set it equal to null
} else {
    $profile_img = $userData['picture']; // Else get the Link of the Image
}
JavaScript中的备选方案

var url = ""; // Image URL

var img_split = url.split("/"); // Split it Again from / (forward slash)

if (img_split[img_split.length - 1] === 'photo.jpg') { // Check if last array is equal to photo.jpg (By Default Image)
   var image = null;
} else {
   var image = url;
}

希望能有所帮助

我一分钟前就试过了。这给了我一个教训“:错。请你澄清一下,如果没有,怎么办?默认为False,或默认为true?@androiddeveloper默认为
False
:如果API中省略了
default
,则表示它的用户设置此字符串似乎已更改,但默认图像包含
aaaaaaaaaa i/aaaaaaaaaaaa
,并以
photo.jpg
结尾,这仍然是真的。
$profile_img_end = explode("/", $userData['picture']); // Exploding the URL and Dividing it into several terms

if (end($profile_img_end) === "photo.jpg") { // Now Simply Check if last part of array is equal to "photo.jpg" which is common in all default images
    $profile_img = null; // If it's default then set it equal to null
} else {
    $profile_img = $userData['picture']; // Else get the Link of the Image
}
var url = ""; // Image URL

var img_split = url.split("/"); // Split it Again from / (forward slash)

if (img_split[img_split.length - 1] === 'photo.jpg') { // Check if last array is equal to photo.jpg (By Default Image)
   var image = null;
} else {
   var image = url;
}