Created
January 1, 2012 03:02
-
-
Save shogo82148/1546087 to your computer and use it in GitHub Desktop.
Facebookにポストするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python2.6 | |
#-*- coding:utf-8 -*- | |
import facebook | |
import cgi | |
import urllib | |
import sys | |
import codecs | |
sys.stdin = codecs.getreader('utf-8')(sys.stdin) | |
sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | |
def main(): | |
access_token = "Your Access Token" | |
FACEBOOK_APP_ID = "Your App ID" | |
FACEBOOK_APP_SECRET = "Your App Secret" | |
if not access_token: | |
args = dict(client_id=FACEBOOK_APP_ID, redirect_uri="http://example.com/", scope = 'status_update,publish_stream,offline_access') | |
print "Please Access Following URL:" | |
print "https://graph.facebook.com/oauth/authorize?" + urllib.urlencode(args) | |
print "And Input Your Code:" | |
args["client_secret"] = FACEBOOK_APP_SECRET | |
args["code"] = raw_input() | |
response = cgi.parse_qs(urllib.urlopen( | |
"https://graph.facebook.com/oauth/access_token?" + | |
urllib.urlencode(args)).read()) | |
access_token = response["access_token"][-1] | |
print "Your Code is", access_token | |
graph = facebook.GraphAPI(access_token) | |
graph.put_object("me", "feed", message=" ".join(sys.argv[1:])) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment