Skip to content

Instantly share code, notes, and snippets.

@sethladd
Created April 27, 2012 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethladd/2510459 to your computer and use it in GitHub Desktop.
Save sethladd/2510459 to your computer and use it in GitHub Desktop.
Instagram API with Dart
#import('dart:html');
#import('dart:json');
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
dataReceived(MessageEvent e) {
var data = JSON.parse(e.data);
print(data);
}
void main() {
// listen for the postMessage from the main page
window.on.message.add(dataReceived);
final client_id = "552faa062fdb495796233f9eb6297be2";
ScriptElement script = new Element.tag("script");
script.src = "https://api.instagram.com/v1/media/popular?client_id=$client_id&callback=callbackForJsonpApi";
document.body.elements.add(script);
}
<!DOCTYPE html>
<html>
<head>
<title>dartstagram</title>
</head>
<body>
<h1>dartstagram</h1>
<h2 id="status">dart is not running</h2>
<script type="application/dart" src="dartstagram.dart"></script>
<script src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
<script type="text/javascript">
function callbackForJsonpApi(s) {
window.postMessage(JSON.stringify(s), '*');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment