Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created July 16, 2012 15:16
Show Gist options
  • Save kimihito/3123277 to your computer and use it in GitHub Desktop.
Save kimihito/3123277 to your computer and use it in GitHub Desktop.
post hashtags tweet to FB group
#!/usr/bin/env python
# coding: utf-8
import facebook
import tweepy
import urllib
#setting twitter
consumer_key = "YOUR_CONSUMER_KEY"
consumer_secret = "YOUR_SECRET_KEY"
access_token = "YOUR_ACCESS_TOKEN"
access_secret = "YOUR_ACCESS_SECRET"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token,access_secret)
api = tweepy.API(auth_handler=auth)
#tweet search
query = u"hashtag"
results = api.search(urllib.quote_plus(query.encode('utf-8')))
word = [r.text + ' ' + "https://twitter.com/" + r.from_user + "/status/" + r.id_str for r in results]
graph = facebook.GraphAPI("YOUR_ACCESS_TOKEN")
feed = graph.get_connections("YOUR_GROUP_ID","feed")
old_m= [f['message'] for f in feed['data']]
for w in word:
if w in old_m:
print "same post!"
else:
graph.put_object("YOUR_GROUP_ID", "feed", message=w.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment