Google+已弃用和GoogleSignInAccount getPhotoUrl()返回null

时间:2019-05-11 22:31:39

标签: android google-api

使用GoogleSignIn登录后,我试图使用GoogleSignInAccount类获取Google个人资料照片网址:

[...]
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
Uri photoUrl = MainActivity.account.getPhotoUrl();
[...]

photoUrl始终为空。我在Stackoverflow(GoogleSignInAccount getPhotoUrl() return null)上读到,如果Google+配置不正确,它将返回NULL。 主要问题是:Google+已于2019年4月2日关闭。

如何立即获取Google个人资料照片的网址?

1 个答案:

答案 0 :(得分:0)

您的代码和官方documentation

都没有错
  

请注意,任何配置文件字段都可以为空,具体取决于您请求的范围以及用户的配置文件包括哪些信息。

Google帐户的

照片网址。如果配置了requestProfile()并且用户确实具有Google+个人资料图片,则只有非null。

由于google plus已被删除,因此import re #create a list of strings company_id = [] #open file contents into a variable company_data = open(r'C:\Users\etherealessence\Desktop\company_data_test.json', 'r', encoding="utf-8") #read the line structure into a variable line_list = company_data.readlines() #stringify the contents so regex operations can be performed line_list = str(line_list) #close the file company_data.close() #assign the regex pattern to a variable pattern = re.compile(r'"id":([^,]+)') #find all instances of the pattern and append the list #https://stackoverflow.com/questions/12870178/looping-through-python-regex-matches for id in re.finditer(pattern, line_list): #print(id) company_id.append(id) #test view the list of company id strings #print(line_list) print(company_id) 返回null