很奇怪。该代码在Chromium中运行良好 - 在授权(oauth2)之后,访问Google云端点以下载信息。但是一旦它被转换为js并在Chrome中打开,授权后,它就永远不会访问云端点(从Google应用引擎日志检查)。 如果它在IE9中打开,即使授权页面也不会显示。 任何帮助表示赞赏。
源代码: example.html的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>example</title>
<link rel="stylesheet" href="example.css">
</head>
<body>
<h1>example</h1>
<div id="container">
<div id="title">
<p>Hello!</p>
</div>
<div id="navigation">
<p> first </p>
</div>
<div id="content">
<p> Content </p>
</div>
<button id="login">Login</button>
</div>
<script type="application/dart" src="example.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
example.css
#navigation {
float:left;
color: #333;
width: 200px;
border: 1px solid #ccc;
background-color: #fff;
min-height: 20px;
margin-bottom: 5px;
box-sizing: border-box;
padding: 5px;
}
#content {
margin-left: 200px;
width: 600px;
height: 600px;
border: 1px solid #ccc;
background-color: #fff;
}
example.dart
import 'dart:html';
import 'package:web_ui/web_ui.dart';
import "packages/dart_terminalendpoint_v1_api_client/lib/terminalendpoint_v1_api_browser.dart" as gdglib;
import "package:google_plus_v1_api/plus_v1_api_browser.dart" as pluslib;
import "package:google_oauth2_client/google_oauth2_browser.dart";
final CLIENT_ID = "----------.apps.googleusercontent.com";
final SCOPES = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/plus.me"];
void main() {
var auth = new GoogleOAuth2(CLIENT_ID, SCOPES);
var gdg = new gdglib.Terminalendpoint(auth);
var plus = new pluslib.Plus(auth);
var navigation = query("#navigation");
var content = query("#content");
var loginButton = query("#login");
pluslib.Person me;
void fetch() {
gdg.makeAuthRequests=true;
gdg.terminals.listTerminal().then((l) {
navigation.text = "";
if (l.items != null) {
l.items.forEach((e) {
var p = new ParagraphElement();
p.text = " ${e.emailAddress}: ${e.location}";
navigation.append(p);
});
}
});
}
loginButton.onClick.listen((Event e) {
fetch();
});
}
答案 0 :(得分:1)
我已经使用了discovery_api_client_generator,效果很好。但是,默认情况下,它设置为不进行身份验证,因为库中的变量设置为false,并且无法从外部更改它。如果您在文件client_base.dart中手动编辑生成的库,则下面的browser_client.dart中的代码将执行&#39; right&#39;事情,这是称为认证。
if (makeAuthRequests && auth != null) {
auth.authenticate(request).then((request) => request.send(body));
} else {
request.send(body);
}