Skip to content

Instantly share code, notes, and snippets.

@pdp7
Last active June 23, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdp7/7359910 to your computer and use it in GitHub Desktop.
Save pdp7/7359910 to your computer and use it in GitHub Desktop.
beaglebone black with adafruit 7-segment facebook notifications display
#!/usr/bin/python
import time
import datetime
import facebook
from Adafruit_7Segment import SevenSegment
# ===========================================================================
# title: beaglebone black with adafruit 7-segment facebook notifications display
# author: drew fustini (http://element14.com/fustini)
# blog: http://www.element14.com/community/community/knode/single-board_computers/next-gen_beaglebone/blog/2013/11/08/beaglebone-black-displays-facebook-notifications-on-adafruit-7-segment
#
# method 1: get short term (2 hour) access_token from:
# https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fnotifications
# method 2: get extended (60 days) access_token via instructions at:
# http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html
# note: install the needed python module with "pip install facepy"
# ===========================================================================
access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
segment = SevenSegment(address=0x70)
print "Press CTRL+C to exit"
# Continually update the current unseen notification count on a 4 char, 7-segment display
while(True):
segment.disp.setBufferRow(0, 0);
segment.disp.setBufferRow(1, 0);
segment.disp.setBufferRow(2, 0);
segment.disp.setBufferRow(3, 0);
segment.disp.setBufferRow(4, 0);
graph = facebook.GraphAPI(access_token)
notifications = graph.get_object("me/notifications")
print "notifications"
summary = notifications['summary']
print "summary"
print summary
if summary:
num = summary['unseen_count']
print num
print int(num / 10)
d0 = int(num / 1000)
d1 = int(num / 100)
d3 = int(num / 10)
d4 = num % 10
if d0 != 0:
segment.writeDigit(0, int(num / 1000 ))
if d1 != 0 or num >= 1000:
segment.writeDigit(1, int(num / 100))
if d3 != 0 or num >= 100:
segment.writeDigit(3, int(num / 10))
if d4 != 0 or num >= 10:
segment.writeDigit(4, num % 10)
time.sleep(60)
# from: http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html
# Imports from facepy api
from facepy.utils import get_extended_access_token
#App key/APP ID and App_secret from https://developers.facebook.com/apps
app_id = 'xxxxxxxxxxxxxx'
app_secret = 'yyyyyyyyyyyy'
#Token got by selecting app_name from the drop-down list.
short_lived_access_token = "token"
long_lived_access_token, expires_at = get_extended_access_token(
short_lived_access_token,
app_id, app_secret)
print long_lived_access_token
print expires_at
@pdp7
Copy link
Author

pdp7 commented Nov 7, 2013

Get token from https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fnotifications

WARNING: it expires after a short period of time

TODO: find a way to automatically obtain a new token when expired

@ckshitij
Copy link

ckshitij commented Jun 23, 2016

sir i tried to fetching facebook messages using python script which is mentioned in "http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html" but after i executed that script its shows error message "(#12) fql is deprecated for versions v2.1 and higher"
could u please help me .
screen shot 2016-06-23 at 9 08 39 pm
screen shot 2016-06-23 at 9 08 23 pm
sir this is my code
..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment