forked from MrSwitch/hello.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstagram.js
More file actions
127 lines (109 loc) · 2.46 KB
/
Copy pathinstagram.js
File metadata and controls
127 lines (109 loc) · 2.46 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Instagram
//
(function(hello){
function formatError(o){
if(o && "meta" in o && "error_type" in o.meta){
o.error = {
code : o.meta.error_type,
message : o.meta.error_message
};
}
}
function formatFriends(o){
paging(o);
if(o && "data" in o ){
for(var i=0;i<o.data.length;i++){
formatFriend(o.data[i]);
}
}
return o;
}
function formatFriend(o){
if(o.id){
o.thumbnail = o.profile_picture;
o.name = o.full_name || o.username;
}
}
// Paging
// http://instagram.com/developer/endpoints/
function paging(res){
if("pagination" in res){
res['paging'] = {
next : res['pagination']['next_url']
};
delete res.pagination;
}
}
hello.init({
instagram : {
name : 'Instagram',
login: function(p){
// Instagram throws errors like "Javascript API is unsupported" if the display is 'popup'.
// Make the display anything but 'popup'
p.qs.display = '';
},
oauth : {
// http://instagram.com/developer/authentication/
version : 2,
auth : 'https://instagram.com/oauth/authorize/',
grant : 'https://api.instagram.com/oauth/access_token'
},
// Refresh the access_token once expired
refresh : true,
scope : {
basic : 'basic',
friends : 'relationships',
photos : ''
},
scope_delim : ' ',
base : 'https://api.instagram.com/v1/',
get : {
'me' : 'users/self',
'me/feed' : 'users/self/feed?count=@{limit|100}',
'me/photos' : 'users/self/media/recent?min_id=0&count=@{limit|100}',
'me/friends' : 'users/self/follows?count=@{limit|100}',
'me/following' : 'users/self/follows?count=@{limit|100}',
'me/followers' : 'users/self/followed-by?count=@{limit|100}'
},
wrap : {
me : function(o){
formatError(o);
if("data" in o ){
o.id = o.data.id;
o.thumbnail = o.data.profile_picture;
o.name = o.data.full_name || o.data.username;
}
return o;
},
"me/friends" : formatFriends,
"me/following" : formatFriends,
"me/followers" : formatFriends,
"me/photos" : function(o){
formatError(o);
paging(o);
if("data" in o){
for(var i=0;i<o.data.length;i++){
var d = o.data[i];
if(d.type !== 'image'){
o.data.splice(i,1);
i--;
continue;
}
d.thumbnail = d.images.thumbnail.url;
d.picture = d.images.standard_resolution.url;
d.name = d.caption ? d.caption.text : null;
}
}
return o;
},
"default" : function(o){
paging(o);
return o;
}
},
// Use JSONP
xhr : false
}
});
})(hello);