forked from mogya/oauth-adapter
/
readme
104 lines (95 loc) · 2.92 KB
/
readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Ti.include('lib/oauth_adapter.js');
var oAuthAdapter = new OAuthAdapter(
'YOUR CONSUMER SECRET',
'YOUR CONSUMER KEY',
'HMAC-SHA1'
);
// load the access token for the service (if previously saved)
oAuthAdapter.loadAccessToken('twitter');
//OAuth if need.
if (oAuthAdapter.isAuthorized() == false)
{
var receivePin = function() {
oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token');
oAuthAdapter.saveAccessToken('twitter');
};
// show the authorization UI and call back the receive PIN function
oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?' +
oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token'), receivePin);
}
//TWEET
oAuthAdapter.send({
url:'https://api.twitter.com/1/statuses/update.json',
parameters:[
['status', '@mogyatest test from tmtwit. '+Math.random()]
],
method:'POST',
onSuccess:function(responce){
alert('post succeed');
}
});
//get timeline
oAuthAdapter.send({
url:'https://api.twitter.com/1/statuses/home_timeline.json',
parameters:[
],
method:'GET',
onSuccess:function(response){
alert('got tweets.see info log.');
response = JSON.parse(response);
for(var i=0;i<response.length;i++){
var tweet = response[i];
Ti.API.info(tweet.user.name+':'+tweet.text);
}
}
});
//
// new feature
//
// Google: OAuth for Installed Applications: http://code.google.com/intl/ja/apis/accounts/docs/OAuthForInstalledApps.html
var adapter = new OAuthAdapter(
'anonymous',
'anonymous',
'HMAC-SHA1'
);
adapter.loadAccessToken('google');
if(!adapter.isAuthorized()){
var _createMessage = adapter.createMessage;
adapter.createMessage = function (){
var msg = _createMessage.apply(adapter, arguments);
msg.parameters.push(['scope', 'https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email']);
msg.parameters.push(['oauth_callback', 'oob']);
msg.parameters.push(['xoauth_displayname', 'Hello World']);
msg.parameters.push(['btmpl', 'mobile']);
msg.parameters.push(['hl', 'ja']);
return msg;
};
adapter.getRequestToken('https://www.google.com/accounts/OAuthGetRequestToken', function(token){
adapter.showAuthorizeUI('https://www.google.com/accounts/OAuthAuthorizeToken?' + token, function (){
var indicator = Titanium.UI.createActivityIndicator({
message: 'processing...',
bottom: 10,
height: 50,
width: 10,
style: Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN
});
indicator.show();
adapter.getAccessToken('https://www.google.com/accounts/OAuthGetAccessToken', function (tk){
adapter.saveAccessToken('google');
indicator.hide();
});
});
});
}
adapter.send({
url: 'https://www.googleapis.com/userinfo/email',
method: 'GET',
parameters: [],
stickOAuthParam: true,
onSuccess: function (res){
Titanium.API.debug(res);
},
onError: function (){
Titanium.API.debug("error");
}
});