真奇怪。该代码在 Chromium 中运行良好——授权 (oauth2) 后,访问 Google 云端点以下载信息。但是一旦它转换为 js 并在 Chrome 中打开,授权后,它就永远不会访问云端点(从谷歌应用引擎日志中检查)。如果用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>
例子.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;
}
例子.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();
});
}