{
"dc":"us1",
"login_url":"https://login.mailchimp.com",
"api_endpoint":"https://us1.api.mailchimp.com"
}
OAuth.popup('facebook', function(err, res) { if (err) { // do something with error }
// the access token is res.access_token !
})
OAuth.popup('facebook', function(err, res) { if (err) { // do something with error }
res.get('/me')
.done(function(data) { alert('Hello ' + data.name) }) })
OAuth.popup('twitter', function(err, res) { if (err) { // do something with error }
res.get('/1.1/account/verify_credentials.json') .done(function(data) { alert('Hello ' + data.name) }) })
<html ng-app="demoApp">
<head>
<!-- title, js/css (jquery/bootstrap/angular) -->
<script src="/oauth.js"></script> <script src="/app.js"></script> <link rel="stylesheet" type="text/css" href="/basic.css" /> </head> <body> <div class="container"> <h1>Twitter ~ client-side timeline</h1> <div class="well"> <div class="basic-content" ng-view></div> </div> </div> </body> </html>
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.config(function($routeProvider) {
$routeProvider.when('/timeline', {
templateUrl: '/partials/timeline.html',
controller: 'timelineCtrl'
}).when('/connect', {
templateUrl: '/partials/connect.html',
controller: 'connectCtrl'
}).otherwise({
redirectTo: '/connect'
});
});
<h3>Connect with twitter to see your home timeline</h3>
<button ng-click='connect()' class="btn btn-primary">
<img src="https://oauth.io/api/providers/twitter/logo" />
connect with twitter
</button>
demoApp.controller('connectCtrl', function ($scope,
$rootScope, $location) {
OAuth.initialize("hMOd7zAuUxDSM..."); $scope.connect = function() { OAuth.popup("twitter", function(err, res) { if (err) return alert(err); $rootScope.twitter = res; $location.path('/timeline'); $scope.$apply(); }); } });
<ul id="timeline" ng-repeat="entry in tw_timeline">
<li> <img class="thumb" src="{{entry.user.profile_image_url}}" /> <span class="content"> <span class="author">{{entry.user.name}}</span> <span class="text">{{entry.text}}</span> </span> </li> </ul>
demoApp.controller('timelineCtrl', function ($scope,
$rootScope) {
$rootScope.twitter.get('/1.1/statuses/home_timeline.json')
.done(function(data) { $scope.tw_timeline = data; $scope.$apply(); }); });
$scope.connect = function() {
OAuth.popup("google_drive", function(err, res) {
if (err) return alert(err);
$rootScope.drive = res;
getDriveFile("realtime_test", function (file) {
$rootScope.drive_file = file;
$location.path('/editor');
$scope.$apply();
});
});
}
function getDriveFile(title, callback) {
$rootScope.drive.get({ url: "/drive/v2/files", data: {q: "title = '" + title + "'"} }).done(function(files) { if (files.items.length) return callback(files.items[0]); // create file if it does not exists createDriveFile(title, callback); }); }
function createDriveFile(title, callback) {
$rootScope.drive.post({ url: "/drive/v2/files", data: JSON.stringify({ title: title, mimeType:'application/vnd.google-apps.document'}), contentType: 'application/json' }).done(function(item) { callback(item); }); }
<textarea id="editor" ng-model="file_content"></textarea>
demoApp.controller('editorCtrl', function($scope,
$rootScope) {
$rootScope.drive.get(
$rootScope.drive_file.exportLinks['text/plain'])
.done(function(data) { $scope.file_content = data; $scope.$apply(); $scope.$watch("file_content", function() { $scope.must_save = true; updateFile();
});
}); function updateFile() { // ... } }
function updateFile() {
if ( ! $scope.must_save) return; if ($scope.saving) return setTimeout(updateFile, 50); $scope.saving = true; $scope.must_save = false; $rootScope.drive.put({ url: "/upload/drive/v2/files/" + $rootScope.drive_file.id + + "?uploadType=media", data: $scope.file_content }).always(function() { $scope.saving = false; updateFile(); }); }