Skip to content

Instantly share code, notes, and snippets.

@kvorion
Created May 8, 2011 09:08

Revisions

  1. kvorion revised this gist May 8, 2011. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions comment.py
    Original file line number Diff line number Diff line change
    @@ -24,10 +24,8 @@ def MakeComment(messageId, content):
    formPosts['message'] = content
    data = urllib.urlencode(formPosts)
    print data
    #response = GetJsonResponse(url, data)
    f = urllib.urlopen(url, data)
    print f.read()
    #print response


    feedUrl='https://graph.facebook.com/me/feed?access_token=' + read_token + '&limit=100'
  2. kvorion created this gist May 8, 2011.
    47 changes: 47 additions & 0 deletions comment.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    import simplejson as json
    import urllib2, urllib, string

    read_token = 'abc
    write_token = 'def'

    def GetJsonResponse(requestUrl, content = None):
    request = urllib2.Request(requestUrl)
    response = urllib2.urlopen(request, content)
    result = json.load(response)
    return result

    def GetFirstName(facebookId):
    url = 'https://graph.facebook.com/' + facebookId + '&access_token=' + read_token
    profileInfoJson = GetJsonResponse(url)
    first_name = profileInfoJson['first_name']
    return first_name

    def MakeComment(messageId, content):
    url = 'https://graph.facebook.com/' + messageId + '/comments'
    print url
    formPosts = {}
    formPosts['access_token'] = write_token
    formPosts['message'] = content
    data = urllib.urlencode(formPosts)
    print data
    #response = GetJsonResponse(url, data)
    f = urllib.urlopen(url, data)
    print f.read()
    #print response


    feedUrl='https://graph.facebook.com/me/feed?access_token=' + read_token + '&limit=100'

    response = GetJsonResponse(feedUrl)
    if len(response['data']) != 100:
    print 'error while retrieving data'
    else:
    for counter in range(0, 100):
    if ('message' in response['data'][counter]) and (string.find(response['data'][counter]['message'].lower(), 'happy') != -1) \
    and ('comments' not in response['data'][counter]):
    first_name = GetFirstName(response['data'][counter]['from']['id'])
    thanks_message = 'Thanks ' + first_name
    message_id = response['data'][counter]['id']
    print thanks_message
    MakeComment(message_id, thanks_message)