Exemplo n.º 1
0
def make_test_friends(uid1, user1_access_token, uid2, user2_access_token):
    ''' Make two test users friends. '''
    
    # create friend request from u1 to u2
    url = "FB_GRAPH_BASE_URL"
    url += "/%s/friends/%s" % (uid1, uid2)
    url += "?access_token=%s" % user1_access_token
    
    s = net.post(url)

    if s:
        logger.debug("make_test_friends: created friend request from u1->2:, response: '%s'" % s)
    else:
        logger.error("make_test_friends: Failed to create friend request from u1->u2")
        return False
    
    
    # confirm friend request to u2
    url = "FB_GRAPH_BASE_URL"
    url += "/%s/friends/%s" % (uid2, uid1)
    url += "?access_token=%s" % user2_access_token
    
    s = net.post(url)

    if s:
        logger.debug("make_test_friends: created friend request from u1->2:, response: '%s'" % s)
        return True
    else:
        logger.error("make_test_friends: Failed to create friend request from u1->u2")
        return False
Exemplo n.º 2
0
def create_test_user(app_id, app_access_token, installed=True, permissions=[]):
    ''' Create a test user.  The test user cannot interact with real Facebook users.
    
        app_access_token - application access token
        installed - True/False, Specifies whether the user has authorized the app
        permissions - list of extended permissions the app is granted for the user.
    '''
    
    if installed:
        istr = "true"

    else:
        istr = "false"
        # permissions are only valid if installed is true
        permissions = None
        
    permissions = ",".join(permissions)

    url = FB_GRAPH_BASE_URL
    url += "/%s/accounts/test-users?" % app_id
    url += "access_token=%s" % app_access_token
    url += "&installed=%s" % istr
    url += "&permissions=%s" % permissions
        
    s = net.post(url, {})
    
    if s:
        logger.debug("Create test user, response: '%s'" % s)
        return json.loads(s)
    else:
        logger.error("Failed to create test user")
        return None
Exemplo n.º 3
0
def post_to_wall(access_token, user_id, message, link=None, name=None, description=None, caption=None, picture=None, 
                                                 source=None, wall_filtering=True, allowed_ids=[]):
    ''' Post a message to the user's wall. 
    
        message - message to post
        link - Link attached ot the post
        name - Name of the link
        description - Description of the link
        caption - link caption
        picture - link to the picture included with the post
        source - URL to Flash movie or video file used within the post.
        wall_filtering - flag to avoid making test posts on other people's walls
        
    '''
    
    # first check filtering settings.  for spam filtering, we do not post to user's walls for any sort of test messages.
    if wall_filtering:
        
        if user_id == "me":
            # special user id referring to user whose access token we're throwing about.  always ok, this is only going to be seen in dev
            # code.
            pass
            
        elif user_id not in allowed_ids:
            logger.warn("User '%s' is NOT on the approved list for wall posting.  Skipping" % user_id)
            return
            
        
    url = FB_GRAPH_BASE_URL + "/%s/feed?access_token=%s" % (user_id, access_token)

    #if not caption:
    #    caption = "Spark matcher caption"
        
    data = {
        "message" : message,
    }
    if caption is not None:
        data["caption"] = caption
    if link:
        data["link"] = link
    if name:
        data["name"] = name
    if description:
        data["description"] = description
    if picture:
        data["picture"] = picture
    if source:
        data["source"] = source
            
    
    
    s = net.post(url, data)
    
    # returns info about the post
    if s:
        o = json.loads(s)
        
        # object is a dictionary with just "id" in it, probably meaning the post id.
        logger.error("POST returned: " + s)
        
        return o
    else:
        logger.error("post_to_wall: failed to post to url: %s" % url)
        return None