I am trying to post a message to the wall of a business page. I follow the following steps and everything works fine except that I don't publish the message on the business wall as administrator.
graph = facebook.GraphAPI(access_token='xxx')
If I use graph.put_wall_post(message='test') I publish the text on my personal wall.
With the profile id of business page, graph.put_wall_post(message='test', profile_id='5537xx') I post something like Me > business page
If I try to create the app using the business page, I get the following error:
Users not logged into their personal account cannot access developers.facebook.com
How can I post the message as a text post directly to my business page without error?
You should get an access-token for a page. You are probably getting an access-token for your personal account.
As stated in the Graph API Docs, here and here
With the Pages API, people using your app can post to Facebook as a
Page (...)
Before your app can make calls to read, update, or post to Pages you need to get a page access token. With this token you can view Page settings, make updates to page information and manage a Page.
Therefore, you basically should get the token corresponding to your page
To get the Page access token for a single page call the API endpoint
/{page-id} using an user access token and asking for the field
access_token. You need the permission pages_show_list or manage_pages
to successfully execute this call.
And then make requests to post content, for instance, a message
To post text to a Page's feed, provide a message parameter with the
text along with the Page ID:
POST https://graph.facebook.com/546349135390552/feed?message=Hello
On success, Graph API responds with JSON containing the Page
ID and the ID for the post:
{ "id": "546349135390552_1116689038356556" }
Read the links above and you'll have more information about it.
Related
so in the past few days I've been wondering how this works.
Basically Twitter added a new profile feature where you can put /nft at the end of a profile URL and it would show you if that user owns an NFT that is linked with their profile.
Thing is when you put /nft on a user that does not own an NFT (or hasn't linked one with their profile) the URL is changed to the profile page with an /photo at the end of the URL.
How is this possible without a redirection? There is no 301 status_code on the requests made. Also is it possible to fetch this /photo URL using python?
Example:
Profile with linked NFT:
https://twitter.com/STEP1profit/nft
Profile without linked NFT (URL is changed to /photo):
https://twitter.com/theweeknd/nft
In my Django website, I want to redirect to an external website, authenticate on this external website and then the external website returns an API token that I want to save.
I have instructed the external website to redirect to 127.0.0.1:8000 (my home page) after I have successfully authenticated. When I'm redirected, I have a URL in this format:
http://127.0.0.1:8000/#access_token={token the external website generates}&token_type=Bearer&expires_in={expiry time}.
How can I get the values after the # in the URL? As I understand the values after the # is not sent back to the Django server.
Yeah that is never sent to the server.
What you could do is grab it with some JS, and submit it manually.
window.location.hash // gets you that value
I started recently working on API's and few API providers are not requesting redirect URL while some others are requesting. I have written an algorithmic strategy for trading using python. When I requested for API to Fyers(stockbroker), the team said me to provide a redirect URL. what is a redirect URL? and how to create it?
I have attached image for reference. In the above image, there is a text box for Redirect URL. Can you please explain what exactly is Redirect URL and how to create one for calling API for authentication if my code is on heroku?
The Redirect URL is required by the oAuth workflow: basically the authorisation server will redirect the user back to the URL registered as "Redirect URL" including an authorization code or a token.
If you register a URL like https://myapp.herokuapp.com you will be redirected to
https://myapp.herokuapp.com?access_code=XXX&app_id=YYY
The Redirect URL needs to be a valid accessible page: if the process is manual you just copy the access_code from the browser and use it accordingly.
If it is an application you need to receive the redirect above (the URL is basically your app), fetch the required information (parameters) and implement your logic.
Default Fyers Redirect URL for Testing
Use the default url from fyers
https://trade.fyers.in/api-login/redirect-uri/index.html
Copy the auth key value
Use it in your python app in the second run
You can also use google collab, to run part of code only (authentication) without restarting the whole project
This is my first time dealing with logging in using Facebook credentials. I want to be able to query listings in Airbnb through my account. My original account in Airbnb is through Facebook login. Here is the sample request on airbnb page: http://airbnbapi.org/#login-by-facebook.
I am not sure where can I get my client_id and Facebook's access token. Although it does point to https://developers.facebook.com/docs/facebook-login/access-tokens to get the user access token but, if I understand it correctly, it requires me to create an app. I am not sure what flow of authentication is required for me to use Airbnb API.
I have already looked at Airbnb docs to search for client_id but, of no use.
Here is what I have so far:
import requests
import json
API_URL = "https://api.airbnb.com"
LISTING_ENDPOINT= "https://api.airbnb.com/v2/search_results"
post_query = {
"client_id": "I HAVE NO IDEA WHERE TO GET IT",
"locale": "en-US",
"currency":"USD",
"assertion_type":"https://graph.facebook.com/me"
"assertion":"HOW SHOULD I GET THIS ONE?",
"prevent_account_creation":True
}
# I think this should be able to log me in and I should be able to query listings
_ = requests.post(API_URL, post_query).json()
query = {
"client_id":"FROM ABOVE",
"user_lat": "40.00",
"user_long":"-54.31"
}
listings = requests.get(LISTING_ENDPOINT, json=query).json()
I came across the same problem as you. I figure it out finally. The tool i used is the advanced function of requests library, that is Session(), for saving cookies. The important part for login with a third party account is to find the link we need to post the cookies. The following is my code.
import requests
x=requests.Session() #savig the cookies when you click the "log in with facebook button"
y=requests.Session() #saving the cookies for parsing the airbnb listing.
account={'email':'your_facebook_account','pass':'your_facebook_ps'}
log_in_with_facebook_click=x.post("https://www.airbnb.jp/oauth_connect?from=facebook_login&service=facebook")
#all the cookies up to now is saved in "x"
my_first_time_cookies=x.cookies.get_dict()
real_login_link=log_in_with_facebook_click.url
real_log_in=y.post(real_login_link,account,cookies=my_first_time_cookies)
#the real login link is saved in "log_in_with_facebook"
#pass the cookies and your facebook account information to the real login link
#you should have logged into airbnb.For testing the log in, we do the following. We check the reservation data.
from bs4 import BeautifulSoup
page=1
test=y.get("https://www.airbnb.jp/my_reservations?page="+str(page))
#Remember that the cookies we use to access airbnb website after loggin in is saved in "y"
test_html=BeautifulSoup(test.text,'lxml')
print(test_html.text)
#you should have looked your tenants reservation information.
I want to use facebook api for which I will be needing oauth token, so when the program starts the python program will open the the authentication url by webbrowser.open() method after this the user will will give permission and then facebook will generate access token and redirect to a different link. I need to grab this redirected link and retrieve the access token. How do I grab this redirected url.
Afaik there is no simple way to do this (see Python - Getting url a browser was redirected to)
If you have a WebServer set the redirect page to your server and the get Tokens from there.
Otherwise use the python oauth module.
If you have a fb-app (with id and token) you can do it locally, althrough its not a very good/safe way..