【问题标题】:How to get past "Access Not Configured" error如何克服“未配置访问”错误
【发布时间】:2014-08-21 21:13:51
【问题描述】:

我正在尝试创建一个 Google 电子表格函数来缩短 URL。

我有这个代码:

function shortenUrl(_longurl) {
  var url = UrlShortener.Url.insert({longUrl: _longurl});
  Logger.log('Shortened URL is "%s".', url.id);
}
function testMinifyGoogl() {
    longurl = 'https://maps.google.com/maps';
    shortenUrl(longurl);
}

我有几个 Google 登录 ID 用于测试目的。重复上述两个不同的问题时,我遇到了同样的问题。

在所有情况下,我都会返回:“未配置访问。请使用 Google Developers Console 为您的项目激活 API。(第 7 行,文件“代码”)”

作为参考,我正在阅读:https://developers.google.com/apps-script/advanced/url-shortener。阅读访问要求后,我在脚本编辑器中转到 [资源] >> [高级 Google 服务] 并激活 URL Shortener API。我从那里点击链接到“Google Developers Console”并在那里启用了相同的 API。

是我做错了什么还是服务坏了?

我认为我不需要访问密钥。我已经登录谷歌,以便使用电子表格!此外,当我运行脚本时,我确实收到了访问我的短网址的权限请求!

【问题讨论】:

  • 你是在本地主机上设置的吗?您仍然需要在控制台中获取身份验证密钥并首先访问您的 API 才能使用它。
  • 它是在 Google 电子表格中运行的 Google Apps 脚本。如前所述,我已经在脚本本身和控制台中打开了访问权限。
  • 据我所知,您需要创建一个新项目,然后获取秘密身份验证密钥和用户 ID,并将 localhost 的 url 作为您将访问 api 的位置。只是打开访问没有帮助。
  • 我正在从 Google 电子表格访问。我提供什么网址?
  • 找到应该添加的位置了吗?

标签: google-apps-script url-shortener


【解决方案1】:

网址缩短器仍然运行良好,请参阅应用程序 here(http://goo.gl/RqfaY6)(请求授权)

下面的代码来说明是否有人感兴趣:

var User = new Object(),
Url  = new Object();
User.email = Session.getActiveUser().getEmail();

function doGet() {
  var app = UiApp.createApplication().setTitle('url_shortener');
  var panel = app.createVerticalPanel().setStyleAttributes({'padding':'40px','backgroundColor':'#fafacc'});
  var longUrlLabel = app.createLabel( 'Enter the long url starting with http:// you will receive an email with the short url immediately.' );
  var longUrlBox = app.createTextBox().setName( 'longUrl' ).addClickHandler(app.createClientHandler().forEventSource().setText(''))
  .setText( 'http://' ).setWidth('500');
  var shortUrlLabel = app.createHTML().setId( 'shortUrlLabel' ).setVisible( false );


  var handler = app.createServerHandler( 'buttonOnClickListener' ).addCallbackElement( panel );
  var button = app.createButton( 'SUBMIT',handler ).setStyleAttributes({'border-radius':'5px'});

  var grid = app.createGrid(8,1).setId('grid')
  .setWidget(0,0,longUrlLabel )
  .setWidget(2,0,longUrlBox )
  .setWidget(4,0,button )
  .setWidget(6,0,shortUrlLabel);

  return app.add( panel.add(grid));
}

function buttonOnClickListener( eventInfo ) {
  var app =UiApp.getActiveApplication();
  var toShorten = UrlShortener.newUrl().setLongUrl(eventInfo.parameter.longUrl);
  var shortened = UrlShortener.Url.insert(toShorten);
  Url.short = UrlShortener.Url.insert(toShorten);
  Url.long = eventInfo.parameter.longUrl;
  sendMail();
  app = UiApp.getActiveApplication();
  app.getElementById( 'shortUrlLabel' ).setVisible(true).setHTML('<li>Short url = <b>'+Url.short.id+'</b></li><li>Mail sent ...</li>');
  app.getElementById('grid').setWidget(7,0,app.createAnchor('test (with redirect warning)', Url.short.id));

  return app; 
}

function sendMail() {
  GmailApp.sendEmail( User.email, "UrlShortener", 'Long url (original) = '+Url.long+"\n\n\nShort url = "+Url.short.id);
}


function GetShortUrlClicks() {
  var analytics = UrlShortener.Url.get('http://goo.gl/UxlNQs',{projection:'FULL'}).getAnalytics();
  var clicks = analytics.getWeek();
  Logger.log(clicks);
}

【讨论】:

  • 效果很好。但是我上面的代码现在也可以工作了!一定是我的帐户出现了一些短暂的故障。不过谢谢!
猜你喜欢
  • 2016-06-17
  • 1970-01-01
  • 2013-09-25
  • 2019-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-27
  • 2014-01-24
相关资源
最近更新 更多