Jan-29-2018, 06:53 AM
Hi there! Did not find any relevant topic for my problem.
The situation:
Code in views.py:
I understand that smth is wrong with user access token. It seems to be a simple question but I`m frozen.
I read Facebook SDK docs and OpenGraph API docs but can`t understand wtf.
How can I handle the issue?
The situation:
- Developing Django-based web-application.
- Authorization via Facebook using django-allauth - it is done, works well.
- Need to view Facebook friends on the user's profile using Facebook OpenGraph API - the problem is here!
Code in views.py:
import facebook import requests import json @login_required def user_friendlist(request): #Trying to get data from Facebook using OpenGraph API FB_APP_ID = {my_app_id} FB_APP_SECRET = {my_app_secret} try: r = requests.get( 'https://graph.facebook.com/oauth/access_token?client_id=' + FB_APP_ID + '&client_secret=' + FB_APP_SECRET + '&grant_type=client_credentials') r_json = r.json() ACCESS_TOKEN = r_json['access_token'] graph = facebook.GraphAPI(access_token = ACCESS_TOKEN) current_user = graph.get_object('me') friends = graph.get_connections(id = current_user['id'], connection_name = 'friends') #Friendlist friendlist = [] friends['data'][0]['name'] for friend in friends['data']: friendlist.append(friend['name']) except Exception: friendlist = "Importing friendlist failed!" return render( request, 'users/user_profile.html', {'friendlist': friendlist} )
I read Facebook SDK docs and OpenGraph API docs but can`t understand wtf.
How can I handle the issue?