【发布时间】:2017-06-25 19:36:40
【问题描述】:
当我尝试运行 Appscript 时出现错误..
[17-02-08 01:00:35:160 PST] 打开以下 URL 并重新运行脚本:https://accounts.google.com/o/oauth2/auth?client_id=317559754348->0p1ti3fmjae175i06hn07jrbia6701q6.apps.googleusercontent.com&response_type=code&redirect_uri=https%3A%2F%2Fscript .google.com%2Fmacros%2FD>%2F1pgAT7ZCwiKrHx_7Iys770hJNRqTYwn9zioe9Qjvmhzc9rfIxO04P8Uum%2Fusercallback&状态= ADEpC8xV9BMj3kqytygKLnjEYT7PX918NJg0i1oSCAsUTRwXcOgdzDStZA3lzGDK98CJ6OOhlDnlYEyyji5rx6P8haao8oDop-> PMQBZsMMjk2Jl_GtsPnsifFDt1XjqSXtCS2Wx6X3fdLDHTlBzfwqvqrinfkHhW1dVw0oNv6-MaqDhimE912Po&范围= HTTPS%3A%2F%2Fwww.googleapis.com%2Fauth>%2Fdevstorage.read_write&ACCESS_TYPE =离线&approval_prompt =力&login_hint = imerrywe%40jaguarlandrover.com
问题是客户端 ID 317559754348-0p1ti3fmjae175i06hn07jrbia6701q6.apps.googleusercontent.com
不再存在。好像不小心被删了。 我已尝试创建新的 Oauth2 凭据,但我的 appscript 想使用旧的。
如何让我的 appscripts 使用新凭据。 ?
问候, 伊恩
// Global Project variables
var CLIENT_ID = 'xxxxxxxxxx-
leuap166eur7gi5ufr6kiau2nqefknci.apps.googleusercontent.com';
var CLIENT_SECRET = 'xxxxxxxxxx';
// OAuth2.0 Access token
var token;
function oAuth() {
// Check we have access to the service
Logger.log(Session.getActiveUser().getEmail());
Logger.log( Session.getEffectiveUser().getEmail());
var service = getService();
Logger.log('Access '+service.hasAccess());
var authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
Logger.log(authInfo.getAuthorizationStatus());
if (!service.hasAccess()) {
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s',
authorizationUrl);
return;
}
}
function getService() {
// Create a new service with the given name. The name will be used when
// persisting the authorized token, so ensure it is unique within the
// scope of the property store.
return OAuth2.createService('xxxxxxxxxx')
// Set the endpoint URLs, which are the same for all Google services.
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
// Set the client ID and secret, from the Google Developers Console.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
// Set the name of the callback function in the script referenced
// above that should be invoked to complete the OAuth flow.
.setCallbackFunction('authCallback')
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties())
// Set the scopes to request (space-separated for Google services).
// this is admin access for the sqlservice and access to the cloud- platform:
.setScope('https://www.googleapis.com/auth/sqlservice.admin
https://www.googleapis.com/auth/cloud-platform')
// Below are Google-specific OAuth2 parameters.
// Sets the login hint, which will prevent the account chooser screen
// from being shown to users logged in with multiple accounts.
.setParam('login_hint', Session.getActiveUser().getEmail())
// Requests offline access.
.setParam('access_type', 'offline')
// Forces the approval prompt every time. This is useful for testing,
// but not desirable in a production application.
.setParam('approval_prompt', 'force');
}
- 这是一个错误。
错误:redirect_uri_mismatch
请求中的重定向 URI 与授权给 OAuth >客户端的不匹配。访问 >1 以更新授权的重定向 URI。
【问题讨论】:
-
您可以访问应用程序脚本项目吗?你知道如何在 IDE 中进行编辑吗?
-
我正在 script.google.com 上编写脚本。脚本之前运行正常。
-
我添加了一个重新创建错误的简单脚本。我尝试将变量设置为不同的 client_id,但似乎忽略了这一点。
-
显示你设置
getService()的代码。客户端 ID 是否真的在您的代码中超过两行?它不会像您在示例中那样工作。 -
感谢您的帮助。慢慢地取得进展,我没有意识到 getservice() 函数存在于某人发送给我并且在我的项目中的不同脚本中。它正在从那里获取代码。我已经添加了代码。它现在正在尝试使用指定的 client_id,但仍未获得授权。当我复制并粘贴授权 url 时,我现在收到另一个错误。我已将其添加到原始帖子中。
标签: google-apps-script google-cloud-platform