###前提・実現したいこと
Python(Django)でUBER EATs風のアプリを作っています。
注文を追加するAPIをPostmanでテストした際に「AccessToken matching query does not exist.」というエラーが発生してしまっています。
アクセストークンはFacebookで発行したものです。
https://developers.facebook.com/tools/accesstoken
###発生している問題・エラーメッセージ
DoesNotExist at /api/customer/order/add/ AccessToken matching query does not exist. Request Method: POST Request URL: http://localhost:8000/api/customer/order/add/?access_token=kNhEuvGmjPbXw1jaN3GIwWKrLyRuTv&restaurant_id=1&address=17%20BKK1&order_details=[%7B%22meal_id%22:%201,%20%22quantity%22:%202%7D] Django Version: 1.11.4 Exception Type: DoesNotExist Exception Value: AccessToken matching query does not exist. Exception Location: /Users/admin/Desktop/myvirtualenv/foodtasker/lib/python3.6/site-packages/django/db/models/query.py in get, line 380 Python Executable: /Users/admin/Desktop/myvirtualenv/foodtasker/bin/python Python Version: 3.6.0 Python Path: ['/Users/admin/Desktop/foodtasker', '/Users/admin/.pyenv/versions/3.6.0/lib/python36.zip', '/Users/admin/.pyenv/versions/3.6.0/lib/python3.6', '/Users/admin/.pyenv/versions/3.6.0/lib/python3.6/lib-dynload', '/Users/admin/Desktop/myvirtualenv/foodtasker/lib/python3.6/site-packages'] Server time: Wed, 16 Aug 2017 12:53:34 +0000
###該当のソースコード
Python
1@csrf_exempt 2def customer_add_order(request): 3 """ 4 params: 5 access_token 6 restaurant_id 7 address 8 order_details (json format), example: 9 [{"meal_id": 1, "quantity": 2},{"meal_id": 2, "quantity": 3}] 10 stripe_token 11 12 return: 13 {"status": "success"} 14 """ 15 16 if request.method == "POST": 17 # Get token 18 access_token = AccessToken.objects.get(token = request.POST.get("access_token"), 19 expires__gt = timezone.now()) 20 21 # Get profile 22 customer = access_token.user.customer 23 24 # Check whether customer has any order that is not delivered 25 if Order.objects.filter(customer = customer).exclude(status = Order.DELIVERED): 26 return JsonResponse({"status": "failed", "error": "Your last order must be completed."}) 27 28 # Check Address 29 if not request.POST["address"]: 30 return JsonResponse({"status": "failed", "error": "Address is required."}) 31 32 # Get Order Details 33 order_details = json.loads(request.POST["order_details"]) 34 35 order_total = 0 36 for meal in order_details: 37 order_total += Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"] 38 39 if len(order_details) > 0: 40 # Step 1 - Create an Order 41 order = Order.objects.create( 42 customer = customer, 43 restaurant_id = request.POST["restaurant_id"], 44 total = order_total, 45 status = Order.COOKING, 46 address = request.POST["address"] 47 ) 48 49 # Step 2 - Create Order details 50 for meal in order_details: 51 OrderDetails.objects.create( 52 order = order, 53 meal_id = meal["meal_id"], 54 quantity = meal["quantity"], 55 sub_total = Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"] 56 ) 57 58 return JsonResponse({"status": "success"})
###補足情報
python-3.6.0
dj-database-url==0.4.2
Django==1.11.4
gunicorn==19.7.1
olefile==0.44
Pillow==4.2.1
pytz==2017.2
whitenoise==3.3.0
psycopg2==2.6.2
django-rest-framework-social-oauth2==1.0.8
django-bootstrap3==9.0.0
djangorestframework==3.4.3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。