From d13ad2f8737c79804b28239401e0c02f5ccdc9c9 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Fri, 29 Jul 2016 18:58:00 +0200 Subject: [PATCH] initial facebook posting stuff --- .../bureau/publicrelations/publicrelations.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/screenless/bureau/publicrelations/publicrelations.py b/screenless/bureau/publicrelations/publicrelations.py index 4d0501e..ac9501e 100644 --- a/screenless/bureau/publicrelations/publicrelations.py +++ b/screenless/bureau/publicrelations/publicrelations.py @@ -1,3 +1,5 @@ +import facebook +import requests import twitter from bureau import Bureau, add_command, add_api @@ -40,6 +42,33 @@ class PublicRelations(Bureau): id_img1 = t_up.media.upload(media=imagedata)["media_id_string"] self.t.t.statuses.update(status="#screenless", media_ids=id_img1) + @add_command("fbpost", "Post to Facebook") + def post_fb(self): + """ + Takes a photograph using the document camera and posts it to Facebook. + """ + photo = self.send("PX", "photo")["photo"] + + access_token = 'EAADixisn70ABADh2rEMZAYA8nGzd6ah8RFZA3URba263aCQ63ajLeTiZC5sgZCyIVSmRZBWReVsO9IuaLibX5RjW9Ja2tTZAbxgrDr1dPJzyGwcGTSV9bW1W4NigN0d9dFIH35W2fZBOkhvuLqOCDCBacIPjXPMxF7DRGyrz5lVHxTc04OlBeRX' + page_id = "screenless" + graph = facebook.GraphAPI(access_token) + #graph.put_object(parent_object=page_id, connection_name='feed', + # message='testing screenless post') + print("uploading photo " + photo) + graph.put_photo(image=open(photo, 'rb'), album_path=page_id + "/photos", + message='test photo') + #files = {"file": ("cam.jpg", open(photo, 'rb'))} + #args = {} + #args["access_token"] = access_token + #args["caption"] = "test cam" + #resp = requests.post(facebook.FACEBOOK_GRAPH_URL + graph.version + "/"\ + # + "me" + "/photos", + # files=files, + # params=args, + # timeout=graph.timeout, + # proxies=graph.proxies) + #print(resp.json()) + @add_command("twtimeline", "Print Recent Tweets") def tw_timeline(self, data=None): """