已弃用的 google plus api 的替代解决方案是啥?

     2023-02-23     69

关键词:

【中文标题】已弃用的 google plus api 的替代解决方案是啥?【英文标题】:What is the alternative solution of deprecated google plus api?已弃用的 google plus api 的替代解决方案是什么? 【发布时间】:2019-06-23 15:43:08 【问题描述】:

Google 宣布在 3 月 7 日弃用所有 google plus api,我正在使用 oauth2 的 google plus api,所以我担心如果是,我的 https://www.googleapis.com/plus/v1/people/me 也会被弃用,而不是替代解决方案。 .

//index.php
<?php 
include('constant.php');
include('google-login-api.php');
// include constant.php
// include google-api library


if(isset($_GET['code'])) 

    $gapi = new GoogleLoginApi();

    // Get the access token 
    $data = $gapi->GetAccessToken(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_REDIRECT_URL, GOOGLE_CLIENT_SECRET, $_GET['code']);





    if(is_array($data) && count($data)>0)
    
        // Get user information
        $user_info = $gapi->GetUserProfileInfo($data['access_token']);

        echo "<pre>";
        print_r($user_info);
    
else
    //html code
    ?>
    <a class="sign-in sign-google" href="<?php echo GOOGLE_API_URL; ?>"><i class="fa fa-google-plus"aria-hidden="true"></i>Sign In with Google</a>
    <?php

?>

//google-login-api.php
<?php

class GoogleLoginApi

    public function GetAccessToken($client_id, $redirect_uri, $client_secret, $code)   
        $url = 'https://accounts.google.com/o/oauth2/token';            

        $curlPost = 'client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&client_secret=' . $client_secret . '&code='. $code . '&grant_type=authorization_code';
        $ch = curl_init();      
        curl_setopt($ch, CURLOPT_URL, $url);        
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
        curl_setopt($ch, CURLOPT_POST, 1);      
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);    
        $data = json_decode(curl_exec($ch), true);
        $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);      
        if($http_code != 200) 
            throw new Exception('Error : Failed to receieve access token');

        return $data;
    

    public function GetUserProfileInfo($access_token)  
        $url = 'https://www.googleapis.com/plus/v1/people/me';          

        $ch = curl_init();      
        curl_setopt($ch, CURLOPT_URL, $url);        
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
        $data = json_decode(curl_exec($ch), true);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);     
        if($http_code != 200) 
            throw new Exception('Error : Failed to get user information');

        return $data;
    


?>

这是我正在使用的代码,它运行完美......但问题是在 3 月 7 日之后仍在运行

【问题讨论】:

这看起来像是一个 XY 问题。您有一个问题,您使用 Google Plus API 解决了这个问题。现在你想要一个不同的解决方案。了解您当前使用的解决方案并不能告诉我们很多事情。您应该解释您要解决的问题。 @Quentin 这种方法已于 3 月 7 日被弃用..是否有任何其他不会被弃用的使用 gmail 登录的解决方案 【参考方案1】:

Google Plus API(或至少 API 的 plus.people 部分)的粗略替代是 Google People API。它基本上做同样的事情(返回用户的配置文件信息),尽管在请求的完成方式和响应的格式方面有一些变化。最大的不同是您需要准确地请求您想要接收的字段。

为了获得information for the user,您需要将$url 设置为类似于

$fields = 'names,emailAddresses';
$url = 'https://people.googleapis.com//v1/people/me?personFields='+$fields;

您可以在reference for people.get 中查看personFields 参数的可能值以及对访问有效的OAuth 范围。

【讨论】:

我不会把 people api 称为 google+ 的替代品。它更像是谷歌联系人的替代品。 它以大致相同的方式提供对个人资料的访问,包括“我”绰号,但我已经澄清了。 替换此网址后,我收到此错误“无法获取用户信息” 这就是您生成的错误。你得到的 HTTP 响应代码是什么?你要求什么范围?您使用了哪些字段?也许更新您的原始问题以包含这些更改,而不删除您的原始代码?【参考方案2】:

更改网址,

$url = 'https://www.googleapis.com/plus/v1/people/me';

到,

$url = 'https://www.googleapis.com/oauth2/v3/userinfo';

我有同样的问题,解决了here

【讨论】:

已弃用的 Plus.PeopleApi.load

】已弃用的Plus.PeopleApi.load【英文标题】:DeprecatedPlus.PeopleApi.load【发布时间】:2016-12-0904:41:42【问题描述】:既然Plus.API在GooglePlayServices9.4中已弃用,那么在Android应用程序上为经过身份验证的用户获取GooglePlus圈子的正确方法是... 查看详情

已弃用的 AudioManger.setStreamMute 的替代方案?

】已弃用的AudioManger.setStreamMute的替代方案?【英文标题】:AlternativefordeprecatedAudioManger.setStreamMute?【发布时间】:2016-01-0812:48:11【问题描述】:AudioManger.setStreamMute现在被api23弃用,最好使用AudioManager.adjustStreamVolume和AudioManager.ADJU... 查看详情

替代已弃用的 AudioManager.isWiredHeadsetOn?

】替代已弃用的AudioManager.isWiredHeadsetOn?【英文标题】:AlternativetothedeprecatedAudioManager.isWiredHeadsetOn?【发布时间】:2013-01-0207:43:44【问题描述】:方法AudioManager.isWiredHeadsetOn()从api级别14被弃用,我们现在如何检测是否连接了有线... 查看详情

macOS 10.8 (Mountain Lion) 之后已弃用的资源 'CurResfile'、'UseResFile' 等的替代 API

】macOS10.8(MountainLion)之后已弃用的资源\\\'CurResfile\\\'、\\\'UseResFile\\\'等的替代API【英文标题】:AlternativeAPIsforresources\'CurResfile\',\'UseResFile\',etc.whichhavebeendeprecatedaftermacOS10.8(MountainLion)macOS10.8(MountainLion)之后 查看详情

BitmapDrawable 已弃用的替代方案

】BitmapDrawable已弃用的替代方案【英文标题】:BitmapDrawabledeprecatedalternative【发布时间】:2012-04-1606:11:56【问题描述】:我有以下代码可以将可绘制对象旋转一定的度数。publicDrawablerotateDrawable(floatangle,Contextcontext)BitmaparrowBitmap=Bitm... 查看详情

OAuth2FeignRequestInterceptor 的替代方案,依赖于已弃用的类

】OAuth2FeignRequestInterceptor的替代方案,依赖于已弃用的类【英文标题】:AlternativeforOAuth2FeignRequestInterceptorthatdependsonadeprecatedclass【发布时间】:2020-05-0511:07:44【问题描述】:免责声明:老实说,我尝试在google/github上搜索,扫描了... 查看详情

寻找现在已弃用的 retryWhen 的替代方案

】寻找现在已弃用的retryWhen的替代方案【英文标题】:LookingforanalternativeofretryWhenwhichisnowDeprecated【发布时间】:2020-10-0616:34:43【问题描述】:我遇到了WebClient和reactor-extra的问题。确实,我有以下方法:publicEmployeegetEmployee(Stringemp... 查看详情

图像中已弃用的 Notification 类的替代方法是啥?

】图像中已弃用的Notification类的替代方法是啥?【英文标题】:WhatisthealternativeforthedeprecatedNotificationclassintheimage?图像中已弃用的Notification类的替代方法是什么?【发布时间】:2014-02-1811:14:20【问题描述】:我打算在android设备的... 查看详情

是否有快速替代已弃用的“SKPaymentTransaction.transactionReceipt”?

】是否有快速替代已弃用的“SKPaymentTransaction.transactionReceipt”?【英文标题】:Isthereafastreplacementfordeprecate`SKPaymentTransaction.transactionReceipt`?【发布时间】:2014-05-1513:41:45【问题描述】:是否有快速替代已弃用的SKPaymentTransaction.tran... 查看详情

已弃用的 Hibernate.createClob(Reader reader, int length) 的替代方法是啥

】已弃用的Hibernate.createClob(Readerreader,intlength)的替代方法是啥【英文标题】:WhatisthealternatefordeprecatedHibernate.createClob(Readerreader,intlength)已弃用的Hibernate.createClob(Readerreader,intlength)的替代方法是什么【发布时间】:2012-02-1601:23:11【 查看详情

已弃用的 NSURLConnection 方法,有替代方法吗?

】已弃用的NSURLConnection方法,有替代方法吗?【英文标题】:DeprecatedNSURLConnectionMethods,isthereanalternative?【发布时间】:2012-02-2814:12:26【问题描述】:我正在设置一个NSURLConnection来访问远程服务器:NSURL*url=[[NSURLalloc]initWithString:proj... 查看详情

iOS 12.0 替代使用已弃用的 archiveRootObject:toFile:

】iOS12.0替代使用已弃用的archiveRootObject:toFile:【英文标题】:iOS12.0AlternativetoUsingDeprecatedarchiveRootObject:toFile:【发布时间】:2019-05-0322:47:12【问题描述】:在iOS12中,archiveRootObject:toFile:已被弃用。任何人都可以提出一种简化的替代... 查看详情

[FFmpeg]啥是已弃用的 avpicture_alloc、avpicture::data 的替代品

】[FFmpeg]啥是已弃用的avpicture_alloc、avpicture::data的替代品【英文标题】:[FFmpeg]whatisreplacementsofavpicture_alloc,avpicture::datawhichweredeprecated[FFmpeg]什么是已弃用的avpicture_alloc、avpicture::data的替代品【发布时间】:2016-04-1204:47:35【问题描... 查看详情

pymxs 替代已弃用的 MaxPlus 实用程序函数

】pymxs替代已弃用的MaxPlus实用程序函数【英文标题】:pymxsalternativestothedeprecatedMaxPlusutilityfunctions【发布时间】:2021-08-2400:11:17【问题描述】:随着Autodesk从3dsMax中删除MaxPlus,我现在不得不重新编写一些代码,并且想知道是否有... 查看详情

channel 或 mutablesharedflow ,哪个是已弃用的 localbroadcastmanager 的更好替代品

】channel或mutablesharedflow,哪个是已弃用的localbroadcastmanager的更好替代品【英文标题】:channelormutablesharedflow,whichoneisabetterreplacementfordeprecatedlocalbroadcastmanager【发布时间】:2021-04-0321:15:20【问题描述】:过去,我在聊天和出租车应... 查看详情

Android:替代已弃用的 Context.MODE_WORLD_READABLE?

】Android:替代已弃用的Context.MODE_WORLD_READABLE?【英文标题】:Android:AlternativetothedeprecatedContext.MODE_WORLD_READABLE?【发布时间】:2012-12-0103:51:09【问题描述】:Fromhere我知道一种写入文件并可供其他应用程序和其他意图访问的方法,... 查看详情

Google Sceneform – 是不是已弃用?有替代品吗? [关闭]

】GoogleSceneform–是不是已弃用?有替代品吗?[关闭]【英文标题】:GoogleSceneform–Isitdeprecated?Anyreplacement?[closed]GoogleSceneform–是否已弃用?有替代品吗?[关闭]【发布时间】:2020-10-0817:05:43【问题描述】:我在我的ARCore项目Sceneform... 查看详情

替代已弃用的 setup_environ() 一次性 django 脚本?

】替代已弃用的setup_environ()一次性django脚本?【英文标题】:Alternativetothedeprecatedsetup_environ()forone-offdjangoscripts?【发布时间】:2013-02-0912:48:39【问题描述】:不久前我使用setup_environ()编写了一个一次性的python脚本,该脚本可以从... 查看详情