/
__init__.py
2069 lines (1697 loc) · 62.4 KB
/
__init__.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python
#
# pyfacebook - Python bindings for the Facebook API
#
# Copyright (c) 2008, Samuel Cormier-Iijima
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Python bindings for the Facebook API (pyfacebook - http://code.google.com/p/pyfacebook)
PyFacebook is a client library that wraps the Facebook API.
For more information, see
Home Page: http://code.google.com/p/pyfacebook
Developer Wiki: http://wiki.developers.facebook.com/index.php/Python
Facebook IRC Channel: #facebook on irc.freenode.net
PyFacebook can use simplejson if it is installed, which
is much faster than XML and also uses less bandwith. Go to
http://undefined.org/python/#simplejson to download it, or do
apt-get install python-simplejson on a Debian-like system.
"""
import sys
import time
import struct
import urllib
import urllib2
import httplib
import hmac
try:
import hashlib
except ImportError:
import md5 as hashlib
import binascii
import urlparse
import mimetypes
# try to use simplejson first, otherwise fallback to XML
RESPONSE_FORMAT = 'JSON'
try:
import json as simplejson
simplejson.loads
except (ImportError, AttributeError):
try:
import simplejson
simplejson.loads
except (ImportError, AttributeError):
try:
from django.utils import simplejson
simplejson.loads
except (ImportError, AttributeError):
try:
import jsonlib as simplejson
simplejson.loads
except (ImportError, AttributeError):
from xml.dom import minidom
RESPONSE_FORMAT = 'XML'
# support Google App Engine. GAE does not have a working urllib.urlopen.
try:
from google.appengine.api import urlfetch
def urlread(url, data=None, headers=None):
if data is not None:
if headers is None:
headers = {"Content-type": "application/x-www-form-urlencoded"}
method = urlfetch.POST
else:
if headers is None:
headers = {}
method = urlfetch.GET
result = urlfetch.fetch(url, method=method,
payload=data, headers=headers)
if result.status_code == 200:
return result.content
else:
raise urllib2.URLError(
"fetch error url=%s, code=%d" %
(url, result.status_code))
except ImportError:
def urlread(url, data=None):
res = urllib2.urlopen(url, data=data)
return res.read()
__all__ = ['Facebook', 'create_hmac']
VERSION = '1.0a2'
FACEBOOK_URL = 'http://api.facebook.com/restserver.php'
FACEBOOK_VIDEO_URL = 'http://api-video.facebook.com/restserver.php'
FACEBOOK_SECURE_URL = 'https://api.facebook.com/restserver.php'
def create_hmac(key, tbhashed):
return hmac.new(key, tbhashed, hashlib.sha1).hexdigest()
class json(object):
pass
# simple IDL for the Facebook API
METHODS = {
# dashboard methods
'dashboard': {
'incrementCount': [
('uid', int, ['optional'])
],
'decrementCount': [
('uid', int, ['optional'])
],
'getCount': [
('uid', int, ['optional'])
],
'setCount': [
('count', int, []),
('uid', int, ['optional'])
],
'getActivity': [
('activity_ids', list, ['optional']),
('uid', int, ['optional'])
],
'publishActivity': [
('activity', json, []),
]
},
'application': {
'getPublicInfo': [
('application_id', int, ['optional']),
('application_api_key', str, ['optional']),
('application_canvas_name', str, ['optional']),
],
},
# admin methods
'admin': {
'getAllocation': [
('integration_point_name', str, []),
],
'getRestrictionInfo': [],
'setRestrictionInfo': [
('format', str, ['optional']),
('callback', str, ['optional']),
('restriction_str', json, ['optional']),
],
# Some methods don't work with access_tokens, the signed option forces
# use of the secret_key signature (avoids error 15 and, sometimes, 8)
'getAppProperties': [
('properties', list, []),
'signed'
],
'setAppProperties': [
('properties', json, []),
'signed'
],
},
# auth methods
'auth': {
'revokeAuthorization': [
('uid', int, ['optional']),
],
'revokeExtendedPermission': [
('perm', str, []),
('uid', int, ['optional']),
],
},
# feed methods
'feed': {
'publishStoryToUser': [
('title', str, []),
('body', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('priority', int, ['optional']),
],
'publishActionOfUser': [
('title', str, []),
('body', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('priority', int, ['optional']),
],
'publishTemplatizedAction': [
('title_template', str, []),
('page_actor_id', int, ['optional']),
('title_data', json, ['optional']),
('body_template', str, ['optional']),
('body_data', json, ['optional']),
('body_general', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('target_ids', list, ['optional']),
],
'registerTemplateBundle': [
('one_line_story_templates', json, []),
('short_story_templates', json, ['optional']),
('full_story_template', json, ['optional']),
('action_links', json, ['optional']),
],
'deactivateTemplateBundleByID': [
('template_bundle_id', int, []),
],
'getRegisteredTemplateBundles': [],
'getRegisteredTemplateBundleByID': [
('template_bundle_id', str, []),
],
'publishUserAction': [
('template_bundle_id', int, []),
('template_data', json, ['optional']),
('target_ids', list, ['optional']),
('body_general', str, ['optional']),
('story_size', int, ['optional']),
],
},
# fql methods
'fql': {
'query': [
('query', str, []),
],
'multiquery': [
('queries', json, []),
],
},
# friends methods
'friends': {
'areFriends': [
('uids1', list, []),
('uids2', list, []),
],
'get': [
('flid', int, ['optional']),
],
'getLists': [],
'getAppUsers': [],
'getMutualFriends': [
('target_uid', int, []),
('source_uid', int, ['optional']),
],
},
# notifications methods
'notifications': {
'get': [],
'send': [
('to_ids', list, []),
('notification', str, []),
('email', str, ['optional']),
('type', str, ['optional']),
],
'sendRequest': [
('to_ids', list, []),
('type', str, []),
('content', str, []),
('image', str, []),
('invite', bool, []),
],
'sendEmail': [
('recipients', list, []),
('subject', str, []),
('text', str, ['optional']),
('fbml', str, ['optional']),
]
},
# profile methods
'profile': {
'setFBML': [
('markup', str, ['optional']),
('uid', int, ['optional']),
('profile', str, ['optional']),
('profile_action', str, ['optional']),
('mobile_fbml', str, ['optional']),
('profile_main', str, ['optional']),
],
'getFBML': [
('uid', int, ['optional']),
('type', int, ['optional']),
],
'setInfo': [
('title', str, []),
('type', int, []),
('info_fields', json, []),
('uid', int, []),
],
'getInfo': [
('uid', int, []),
],
'setInfoOptions': [
('field', str, []),
('options', json, []),
],
'getInfoOptions': [
('field', str, []),
],
},
# users methods
'users': {
'getInfo': [
('uids', list, []),
('fields', list, [('default', ['name'])]),
],
'getStandardInfo': [
('uids', list, []),
('fields', list, [('default', ['uid'])]),
],
'getLoggedInUser': [],
'isAppAdded': [],
'isAppUser': [
('uid', int, []),
],
'hasAppPermission': [
('ext_perm', str, []),
('uid', int, ['optional']),
],
'setStatus': [
('status', str, []),
('clear', bool, []),
('status_includes_verb', bool, ['optional']),
('uid', int, ['optional']),
],
},
# events methods
'events': {
'cancel': [
('eid', int, []),
('cancel_message', str, ['optional']),
],
'create': [
('event_info', json, []),
],
'edit': [
('eid', int, []),
('event_info', json, []),
],
'get': [
('uid', int, ['optional']),
('eids', list, ['optional']),
('start_time', int, ['optional']),
('end_time', int, ['optional']),
('rsvp_status', str, ['optional']),
],
'getMembers': [
('eid', int, []),
],
'invite': [
('eid', int, []),
('uids', list, []),
('personal_message', str, ['optional']),
],
'rsvp': [
('eid', int, []),
('rsvp_status', str, []),
],
'edit': [
('eid', int, []),
('event_info', json, []),
],
'invite': [
('eid', int, []),
('uids', list, []),
('personal_message', str, ['optional']),
],
},
# update methods
'update': {
'decodeIDs': [
('ids', list, []),
],
},
# groups methods
'groups': {
'get': [
('uid', int, ['optional']),
('gids', list, ['optional']),
],
'getMembers': [
('gid', int, []),
],
},
# marketplace methods
'marketplace': {
'createListing': [
('listing_id', int, []),
('show_on_profile', bool, []),
('listing_attrs', str, []),
],
'getCategories': [],
'getListings': [
('listing_ids', list, []),
('uids', list, []),
],
'getSubCategories': [
('category', str, []),
],
'removeListing': [
('listing_id', int, []),
('status', str, []),
],
'search': [
('category', str, ['optional']),
('subcategory', str, ['optional']),
('query', str, ['optional']),
],
},
# pages methods
'pages': {
'getInfo': [
('fields', list, [('default', ['page_id', 'name'])]),
('page_ids', list, ['optional']),
('uid', int, ['optional']),
],
'isAdmin': [
('page_id', int, []),
],
'isAppAdded': [
('page_id', int, []),
],
'isFan': [
('page_id', int, []),
('uid', int, []),
],
},
# photos methods
'photos': {
'addTag': [
('pid', int, []),
('tag_uid', int, [('default', 0)]),
('tag_text', str, [('default', '')]),
('x', float, [('default', 50)]),
('y', float, [('default', 50)]),
('tags', json, ['optional']),
],
'createAlbum': [
('name', str, []),
('location', str, ['optional']),
('description', str, ['optional']),
],
'get': [
('subj_id', int, ['optional']),
('aid', int, ['optional']),
('pids', list, ['optional']),
],
'getAlbums': [
('uid', int, ['optional']),
('aids', list, ['optional']),
],
'getTags': [
('pids', list, []),
],
},
# videos methods
'video': {
'getUploadLimits': [
],
},
# status methods
'status': {
'get': [
('uid', int, ['optional']),
('limit', int, ['optional']),
],
'set': [
('status', str, ['optional']),
('uid', int, ['optional']),
],
},
# fbml methods
'fbml': {
'refreshImgSrc': [
('url', str, []),
],
'refreshRefUrl': [
('url', str, []),
],
'setRefHandle': [
('handle', str, []),
('fbml', str, []),
],
},
# SMS Methods
'sms': {
'canSend': [
('uid', int, []),
],
'send': [
('uid', int, []),
('message', str, []),
('session_id', int, []),
('req_session', bool, []),
],
},
'data': {
'getCookies': [
('uid', int, []),
('string', str, ['optional']),
],
'setCookie': [
('uid', int, []),
('name', str, []),
('value', str, []),
('expires', int, ['optional']),
('path', str, ['optional']),
],
},
# connect methods
'connect': {
'registerUsers': [
('accounts', json, []),
],
'unregisterUsers': [
('email_hashes', json, []),
],
'getUnconnectedFriendsCount': [
],
},
'links': {
'post': [
('url', str, []),
('comment', str, []),
('uid', int, []),
('image', str, ['optional']),
('callback', str, ['optional']),
],
'preview': [
('url', str, []),
('callback', str, ['optional']),
],
},
# stream methods (beta)
'stream': {
'addComment': [
('post_id', int, []),
('comment', str, []),
('uid', int, ['optional']),
],
'addLike': [
('uid', int, ['optional']),
('post_id', int, ['optional']),
],
'get': [
('viewer_id', int, ['optional']),
('source_ids', list, ['optional']),
('start_time', int, ['optional']),
('end_time', int, ['optional']),
('limit', int, ['optional']),
('filter_key', str, ['optional']),
],
'getComments': [
('post_id', int, []),
],
'getFilters': [
('uid', int, ['optional']),
],
'publish': [
('message', str, ['optional']),
('attachment', json, ['optional']),
('action_links', json, ['optional']),
('target_id', str, ['optional']),
('uid', str, ['optional']),
],
'remove': [
('post_id', int, []),
('uid', int, ['optional']),
],
'removeComment': [
('comment_id', int, []),
('uid', int, ['optional']),
],
'removeLike': [
('uid', int, ['optional']),
('post_id', int, ['optional']),
],
},
# livemessage methods (beta)
'livemessage': {
'send': [
('recipient', int, []),
('event_name', str, []),
('message', str, []),
],
},
# dashboard methods (beta)
'dashboard': {
# setting counters for a single user
'decrementCount': [
('uid', int, []),
],
'incrementCount': [
('uid', int, []),
],
'getCount': [
('uid', int, []),
],
'setCount': [
('uid', int, []),
('count', int, []),
],
# setting counters for multiple users
'multiDecrementCount': [
('uids', list, []),
],
'multiIncrementCount': [
('uids', list, []),
],
'multiGetCount': [
('uids', list, []),
],
'multiSetCount': [
('uids', list, []),
],
# setting news for a single user
'addNews': [
('news', json, []),
('image', str, ['optional']),
('uid', int, ['optional']),
],
'getNews': [
('uid', int, []),
('news_ids', list, ['optional']),
],
'clearNews': [
('uid', int, []),
('news_ids', list, ['optional']),
],
# setting news for multiple users
'multiAddNews': [
('uids', list, []),
('news', json, []),
('image', str, ['optional']),
],
'multiGetNews': [
('uids', json, []),
],
'multiClearNews': [
('uids', json, []),
],
# setting application news for all users
'addGlobalNews': [
('news', json, []),
('image', str, ['optional']),
],
'getGlobalNews': [
('news_ids', list, ['optional']),
],
'clearGlobalNews': [
('news_ids', list, ['optional']),
],
# user activity
'getActivity': [
('activity_ids', list, ['optional']),
],
'publishActivity': [
('activity', json, []),
],
'removeActivity': [
('activity_ids', list, []),
],
},
# comments methods (beta)
'comments': {
'add': [
# text should be after xid/object_id, but is required
('text', str, []),
# One of xid and object_is is required. Can this be expressed?
('xid', str, ['optional']),
('object_id', str, ['optional']),
('uid', int, ['optional']),
('title', str, ['optional']),
('url', str, ['optional']),
('publish_to_stream', bool, [('default', False)]),
],
'remove': [
# One of xid and object_is is required. Can this be expressed?
('xid', str, ['optional']),
('object_id', str, ['optional']),
# comment_id should be required
('comment_id', str, ['optional']),
],
'get': [
# One of xid and object_is is required. Can this be expressed?
('xid', str, ['optional']),
('object_id', str, ['optional']),
],
}
}
def __fixup_param(name, klass, options, param):
optional = 'optional' in options
default = [x[1] for x in options if isinstance(x, tuple) and x[
0] == 'default']
if default:
default = default[0]
else:
default = None
if param is None:
if klass is list and default:
param = default[:]
else:
param = default
if klass is json and isinstance(param, (list, dict)):
param = simplejson.dumps(param)
return param
def __generate_facebook_method(namespace, method_name, param_data):
# This method-level option forces the method to be signed rather than using
# the access_token
signed = False
if 'signed' in param_data:
signed = True
param_data.remove('signed')
# a required parameter doesn't have 'optional' in the options,
# and has no tuple option that starts with 'default'
required = [x for x in param_data if 'optional' not in x[2] and not [
y for y in x[2] if isinstance(y, tuple) and y and y[0] == 'default']]
def facebook_method(self, *args, **kwargs):
params = {}
for i, arg in enumerate(args):
params[param_data[i][0]] = arg
params.update(kwargs)
for param in required:
if param[0] not in params:
raise TypeError("missing parameter %s" % param[0])
for name, klass, options in param_data:
if name in params:
params[name] = __fixup_param(
name, klass, options, params[name])
return self(method_name, params, signed=signed)
facebook_method.__name__ = method_name
facebook_method.__doc__ = "Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=%s.%s" % (
namespace, method_name)
return facebook_method
class Proxy(object):
"""Represents a "namespace" of Facebook API calls."""
def __init__(self, client, name):
self._client = client
self._name = name
def __call__(
self,
method=None,
args=None,
add_session_args=True,
signed=False):
# for Django templates
if method is None:
return self
if add_session_args:
self._client._add_session_args(args)
return self._client(
'%s.%s' %
(self._name, method), args, signed=signed)
# generate the Facebook proxies
def __generate_proxies():
for namespace in METHODS:
methods = {}
for method, param_data in METHODS[namespace].iteritems():
methods[method] = __generate_facebook_method(
namespace, method, param_data)
proxy = type('%sProxy' % namespace.title(), (Proxy,), methods)
globals()[proxy.__name__] = proxy
__generate_proxies()
class FacebookError(Exception):
"""Exception class for errors received from Facebook."""
def __init__(self, code, msg, args=None):
self.code = code
self.msg = msg
self.extra_args = args
Exception.__init__(self, code, msg, args)
def __str__(self):
return 'Error %s: %s' % (self.code, self.msg)
class AuthProxy(AuthProxy):
"""Special proxy for facebook.auth."""
def getSession(self):
"""Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=auth.getSession"""
args = {}
try:
args['auth_token'] = self._client.auth_token
except AttributeError:
raise RuntimeError('Client does not have auth_token set.')
try:
args['generate_session_secret'] = self._client.generate_session_secret
except AttributeError:
pass
result = self._client('%s.getSession' % self._name, args)
self._client.session_key = result['session_key']
self._client.uid = result['uid']
self._client.secret = result.get('secret')
self._client.session_key_expires = result['expires']
return result
def createToken(self):
"""Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=auth.createToken"""
token = self._client('%s.createToken' % self._name)
self._client.auth_token = token
return token
class FriendsProxy(FriendsProxy):
"""Special proxy for facebook.friends."""
def get(self, **kwargs):
"""Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=friends.get"""
if not kwargs.get('flid') and self._client._friends:
return self._client._friends
return super(FriendsProxy, self).get(**kwargs)
class PhotosProxy(PhotosProxy):
"""Special proxy for facebook.photos."""
def upload(
self,
image,
aid=None,
uid=None,
caption=None,
size=(
720,
720),
filename=None,
callback=None):
"""Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=photos.upload
size -- an optional size (width, height) to resize the image to before uploading. Resizes by default