UNPKG

hellojs-xiaotian

Version:

A clientside Javascript library for standardizing requests to OAuth2 web services (and OAuth1 - with a shim)

68 lines (57 loc) 1.49 kB
<!DOCTYPE html> <link rel="stylesheet" href="/adorn/adorn.css"/> <script src="/adorn/adorn.js" async></script> <script src="client_ids.js"></script> <script src="../src/hello.polyfill.js"></script> <script src="../src/hello.js"></script> <script src="../src/modules/twitter.js"></script> <title>hello( twitter )</title> <h1>hello( twitter )</h1> <button id='login' onclick="login('twitter');">Twitter</button> <div id="result"></div> <script class="pre"> function login(network){ // Twitter instance var twitter = hello(network); // Login twitter.login().then( function(r){ // Get Profile return twitter.api('me'); }, log ) .then( function(p){ // Put in page document.getElementById('login').innerHTML = "<img src='"+ p.thumbnail + "' width=24/>Connected to "+ network+" as " + p.name; }, log ); } </script> <script class="pre"> hello.init({ 'twitter' : TWITTER_CLIENT_ID }, { redirect_uri:'../redirect.html', oauth_proxy: OAUTH_PROXY_URL }); </script> <h2>Tweet</h2> <form> <label>message</label><textarea id="message"></textarea> <br /> <label>media</label><input type="file" id="file"/> </form> <script class="pre"> function tweet(){ var message = document.getElementById('message').value; var files = document.getElementById('file').files; hello('twitter').api('me/share', 'POST', { message : message, file : file }).then(log,log); } </script> <button onclick="tweet()">Tweet</button> <script> function log(){ console.log(arguments); } </script>