Beispiel #1
0
def get_facebook_access_token():

    payload = {'grant_type': 'client_credentials',
               'client_id': FACEBOOK.get('app_id'),
               'client_secret': FACEBOOK.get('secret')}

    url = '{0}/oauth/access_token?'.format(FACEBOOK.get('graph_url'))

    access_token_response = requests.post(url, params=payload)

    access_token = access_token_response.content.split("=")[1]

    return access_token
    def test_facebook_access_token(self):
        url = '{0}/oauth/access_token?'.format(FACEBOOK.get('graph_url'))

        httpretty.register_uri(httpretty.POST, url,
                               body="'access_token=28252560|CcNsxMwOhoJTe'")

        access_token = get_facebook_access_token()

        self.assertEqual(access_token, "28252560|CcNsxMwOhoJTe'")
    def test_facebook_user_data(self):
        # config vars
        facebookId = "10011010101"
        access_token = '282525608440728|CcNsxMwOhoJTe'
        url_token = '{0}/oauth/access_token?'.format(FACEBOOK.get('graph_url'))

        httpretty.register_uri(httpretty.POST, url_token,
                               body="'access_token=28252560|CcNsxMwOhoJTe'")

        user_data_url = "{0}/{1}/?&access_token={2}".format(
                     FACEBOOK.get('graph_url'),
                     facebookId,
                     access_token)

        httpretty.register_uri(httpretty.GET, user_data_url,
                               body='{"id":"10011010101","name": "Arthur"}')

        user_data_response = get_facebook_user_data(facebookId)

        self.assertEqual(user_data_response.json().get('id'), facebookId)
Beispiel #4
0
def get_facebook_user_data(facebookId):
    access_token = get_facebook_access_token()

    user_data_url = "{0}/{1}/?&access_token={2}".format(
                     FACEBOOK.get('graph_url'),
                     facebookId,
                     access_token)

    logger.info('Get Facebook User information facebookId={}'.format(
                                                              facebookId))

    user_data_response = requests.get(user_data_url)

    return user_data_response