You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google YouTube API OOB迁移问题:Loopback模式无法实现原OOB效果

Google OAuth OOB弃用后迁移环回地址的问题

我之前使用Google API的OOB方法,重定向URL为:

urn:ietf:wg:oauth:2.0:oob

但近期该方法已被Google弃用,需迁移至采用环回地址的桌面API。

我尝试了环回地址方法但无法正常工作,相关代码如下:

$client = new Google\Client();      
$client->setAuthConfig($dir . 'google/vendor/credentials.json');

$socket = new SocketServer('127.0.0.1','0');
$redirect = $socket->server;
//$redirect = 'urn:ietf:wg:oauth:2.0:oob';

// readyonly
$client->setScopes(array('https://www.googleapis.com/auth/youtube.readonly','https://www.googleapis.com/auth/youtube.force-ssl','https://www.googleapis.com/auth/yt-analytics.readonly'));
$client->setRedirectUri($redirect);
$client->setAccessType('offline');
$client->setPrompt('consent');
$client->setIncludeGrantedScopes(true);   // incremental auth

若将重定向URL改为http://localhost可以工作,但无法实现原OOB方法的效果。

更新

使用以下代码后出现错误:

$client->setRedirectUri("http://127.0.0.1");
$client->setPrompt('select_account consent');

错误截图:
OAuth错误截图

恳请告知如何实现与原OOB方法一致的效果。


内容的提问来源于stack exchange,提问作者Mohammad Umer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 19:15:48