facebook graph Api: Posting on page: permission issue - python

I am trying to develop a app which will post on user's Facebook page.
Steps I followed are:
1.Created a fb App, with permission : manage_pages and publish_actions
2.Redirected user to 'https://www.facebook.com/dialog/oauth
With parameters:
client_id=FACEBOOK_APP_ID
redirect_uri=FACEBOOK_REDIRECT_URL
scope=manage_pages,publish_actions
Where user allowed app against each permissions
3.On call back url (FACEBOOK_REDIRECT_URL), cought CODE sent by facebook api
4.Now I sent get request to url = https://graph.facebook.com/oauth/access_token with parameters:
'client_id':FACEBOOK_APP_ID
'redirect_uri':FACEBOOK_REDIRECT_URL
'client_secret':FACEBOOK_SECRET_KEY,
'code':CODE
from respose sent by facebook, I filtered TOKEN
5.sent get request to url = https://graph.facebook.com/me/accounts. with parameters:
'access_token':TOKEN
from response I received, I saved page id as PAGE_ID, page_token as PAGE_TOKEN
6.I tried to post something on user's facebook page, I sent post request to url = https://graph.facebook.com/PAGE_ID/feed , with parameters:
'access_token':TOKEN'
'message': MESSAGE_TEXT,
Snap! in response I received:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
I couldn't figure out What mistake I am committing, Do I need to get my app reviewed before posting ? If yes, How can I test my app?
I also tried this by creating a test user. I got the same error.

Thanks to #dhana,
In order to Post on a facebook page, App need manage_pages and publish_action app centre permission, and manage_pages , publish_action and status_update scope while requesting
url = https://www.facebook.com/dialog/oauth?\
client_id='+FACEBOOK_APP_ID+'&\
redirect_uri=' +FACEBOOK_REDIRECT_URL+'&\
scope=manage_pages,publish_actions,status_update

Related

Instagram Basic Display API - Unsupported post request error

I am trying to use the Instagram Basic Display API to post an image to my Instagram account using Python and the requests library. However, I am getting a 400 error with the following message:
{'error': {'message': "Unsupported post request. Object with ID '{user_id}' does not exist, cannot be loaded due to missing permissions, or does not support this operation", 'type': 'IGApiException', 'code': 100, 'error_subcode': 33, 'fbtrace_id': '{fbtrace_id}'}}
OR I get
{'error': {'message': "Unsupported post request. Object with ID 'media' does not exist, cannot be loaded due to missing permissions, or does not support this operation", 'type': 'IGApiException', 'code': 100, 'error_subcode': 33, 'fbtrace_id': '{fbtrace_id}'}}
When trying to make a POST request to "https://graph.instagram.com/me/media"
I have checked that I have the instagram_manage_insights permission and that the user ID is correct. Although I am not too sure I set up the API correctly as I followed a video. But I made an Instagram professional account and linked it to my facebook account, I then signed up at the Facebook Developers Page, then I created a new app and added my instagram account as an instagram tester and went onto instagram and accepted the invite, then I copied my token from the developers page and my user id from the Apps and Websites area on instagram
I used the following code to post an image to my Instagram account:
import requests
# Set up the API endpoint, parameters, and image file
endpoint = 'https://graph.instagram.com/{user_id}/media'
params = {
'access_token': '{access_token}'
}
files = {'file': ('temp.jpg', open('temp.jpg', 'rb'))}
# Make the POST request
response = requests.post(endpoint, params=params, files=files)
# Print the response
print(response.status_code)
print(response.json())
I expected the image to be successfully posted to my Instagram account and to receive a 200 status code in the response.

What Headers and Data to Send With My Post Request

Very beginner to web. I'm trying to login my router's configuration page which resides at 192.168.1.1 address. There is an authorization process and I inspected the post request being sent when logged in, via dev-tools of the browser. The "Form Data" includes these arguments:
Username: admin
Password: pass
action: login
Response code is 301 (Moved Temporarily) however, when I try to send a post request with python, the response code is 200 and the returned html prints the login layout. Also there are no cookies returned back except this "_TESTCOOKIESUPPORT=1". My code below:
import requests
data = {
"Username": 'admin',
"Password": 'pass',
"action": 'login'
}
session = requests.session()
response = session.post("http://192.168.1.1", data=data)
print(response)
print(response.cookies)
Also when I run my code and refresh the login page from browser I get "wrong credentials" error from the page. What's wrong with my post request?

Getting "Invalid csrf token" message while requesting for http://www.sonyliv.com/api/v2/vod/search API in chrome postman

While requesting http://www.sonyliv.com/api/v2/vod/search API, I am getting "Invalid csrf token" message in chrome postman.
{
"code": "403",
"name": "Bad Request",
"message": "Invalid csrf token"
}
When I look to Chrome Inspect Element > Network tab in Headers section, I found
"X-XSRF-TOKEN:tGXcHOmy-ro-GQfTestDSAp8EINq85dwHpdU"
as a token but this token is changed in every session, how can i pass X-XSRF-TOKEN value in my request to get the required result.
Please Help.
The idea of the CSRF tokens is that you can't call an API service if you're not doing it from the expected form, that's why it always changes its value.
I'm guessing you're trying to use that API not officially... so what you could try is to GET the base website and store in a cookie jar all the cookies it sends you and then try to query the search endpoint.
That way your request will include the XSRF token and the rest of the cookies and hopefully the server will think you request is legit.
Hope it helps

Token error when sending Wechat message with Python

I have a Wechat subscribe page, and I set up in https://admin.wechat.com/ a token as well as the webhook URL of my server myserver.com/wechat/webhook
My server Python code authenticates Wechat server with signature check, nonce and timestamp and I'm able to receive messages from Wechat to my webhook.
But I can't send messages from my server to Wechat, I'm using the following code and the token set in the admin console as previously, and following the previous docs:
http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages
# Parse the received WeChat message
message = xmltodict.parse(message)
content = message['xml']['Content']
fromUser = message['xml']['FromUserName']
toUser = message['xml']['ToUserName']
createdTime = message['xml']['CreateTime']
# reply to message
post_data = {
"touser": fromUser,
"msgtype": "text",
"text":
{
"content": "Thanks for your message"
}
}
api_url = 'https://api.wechat.com/cgi-bin/message/custom/send?access_token=' + token
response = requests.post(api_url, data=post_data)
content = response.content
This is the error that I'm getting:
{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [udQ9ka0880vr32!]"}
What token am I supposed to use? Or what could be the error? Thanks
I think it might be a permission problem... In my Wechat page admin console, it says I have Permission obtained for Auto-reply, but not for Service API. Anyone can confirm this?
Indeed I tested successfully instantly replying to POST messages with an http response (Auto-reply or callback) http://admin.wechat.com/wiki/index.php?title=Callback_Messages
And the Service API seems to not be working (which was the purpose of my question) http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages

facebook authorization error (fandjango)

I'm trying to make my first facebook tab app with django.
I did some resarch and found out that fandjago is the best.
So I'm using it , but when I try to require users to authorize I use the decorator
facebook_authorization_required
see : https://fandjango.readthedocs.org/en/latest/usage/authorization.html
I get the following error :
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
with this url:
https://graph.facebook.com/oauth/authorize?scope=publish_stream%2C+publish_actions%2C+user_photos&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fpages%2FWissals-testing%2F368147096656989%3Fid%3D368147096656989%26sk%3Dapp_269443246412431&client_id=269443246412431
This is my redirect uri :
facebook_redirect_uri = "https://www.facebook.com/pages/mypage-testing/36814709662989?id=36814709686989&sk=app_26944328962431"
Please tell me what I am doing wrong, I searched all topics related to th eissu but couldn't figure it out
EDITED
It worked,I had to add my url in my app configuration "Valid OAuth redirect URIs"
But the problem now is that it gets me out of my app to that url, although I need it to stay on the app!!
I'm taking a guess here,
you might need to set FANDJANGO_AUTHORIZATION_DENIED_VIEW to fully contain your canvas url
I finlly solved it
I had to add the same url of my facebook_redirect_uri to my app settings in facebook, advanced tab, field named : Valid OAuth redirect URIs
The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings,
A Canvas URL of the form
https://apps.facebook.com/YOUR_APP_NAMESPACE
or a Page Tab URL of the form
https://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID

Categories

Resources