I've playing around in Python and the Facebook API - I'm fairly new to it! I'm copying and pasting an access token into my Python app from the Graph API Explorer as oauth_access_token manually just before execution. The simple app is a loop which performs some actions based on the status of some inputs. The loop also refreshes the token so that once the app is started with a new token, it should keep going for a longer amount of time. Snippet posted below, with IDs anonymized:
oauth_access_token="ABCDEFGHIJL"
auth_str="/oauth/access_token?grant_type=fb_exchange_token&client_id=XYZ1ABC&client_secret=[ABC2XYZ&fb_exchange_token="+oauth_access_token
graph = facebook.GraphAPI(oauth_access_token)
oauth_access_token = str(graph.request(auth_str)['access_token'])
print oauth_access_token
profile = graph.request("/me/notifications")
profile2 = graph.request("/me/inbox?fields=unseen")
I realize this isn't particularly elegant way of doing it. Bizarrely, when I do this on Windows, it works fine and I have access to the my notifcations and messages. When I do this on my Mac or Ubunutu it doesn't work and I get this error...I think it has something to do with Encoding, but I'm not sure what nor how to fix it?
Malformed access token ABCDEFGHIJK?access_token=ABCDEFGHIJK
Related
I am not sure if i can ask about the Spotify API but saw no other subreddit to put in.
I am trying to connect to Spotify API without the use of external packages (like Spotipy).
I am reading their documentation here:
I decided to use the PKCE since I want to distribute a software and the user only needs to give their client_id (its open source)
In that case, I need to create a "code challenge", this is what I have:
SpotifyCodeChallenge = base64.b64encode(hashlib.sha256(SpotifyCodeVerifier.encode()))
Yet this is the error I get:
How would I fix this?
SpotifyCodeChallenge = base64.b64encode(hashlib.sha256(SpotifyCodeVerifier.encode('utf-8')).digest())
This will prob do it.
I'm currently attempting to use spotipy, a python3 module, to access and edit my personal Spotify premium account. I've followed the tutorial on https://github.com/plamere/spotipy/blob/master/docs/index.rst using the util.prompt_for_user_token method by entering the necessary parameters directly (username, client ID, secret ID, scope and redirect uri). Everything seems to be fine up to this part. My code (fillers for username, client id and client secret for security reasons) :
code
It opens up my default web browser and redirects me to my redirect url with the code in it. At this point, I copy and paste the redirect url (as prompted) and hit enter. It returns the following error:
Error
My redirect uri is 'http://google.com/' for this specific example. However, I've tried multiple redirect uris but they all seem to produce the same error for me. (and yes, I did set my redirect uri as whitespace for my application). I've spent hours trying to fix this issue by looking at online tutorials, trying different redirect urls, changing my code but have yet to make any progress. I'm hoping I am just overlooking a simple mistake here! Any feedback on how to fix this is much appreciated!
If it matters: I'm using the IDE PyCharm.
I had to use two different solutions to deal with the redirect_uri issue depending on which IDE I was using. For Jupyter Lab/Notebook, I could use a localhost for the redirect_url
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="your_client_id", client_secret="your_client_secret", redirect_uri="https://localhost:8890/callback/", scope="user-library-read"))
For Google Colab, I had to use a publicly accessible website. I think "https://google.com/" should work but I used my band's website so I'd remember that the redirect_uri had to match the one in your Spotify Develop dashboard settings.
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="your_client_id", client_secret="your_client_secret", redirect_uri="https://yourwebsite.com/", scope="user-library-read"))
I just ended up using my bands website because it was easier for me to remember. Make sure to go to the Spotify developer dashboard (https://developer.spotify.com/dashboard/applications) and match the redirect_uri with what you are planning to use at that time.
I think it is your redirect URL - working for me with:
import os
import spotipy.util as util
# credentials
user = 'username'
desired_scope = 'playlist-modify-private'
id = os.environ.get('SPOT_CLIENT')
secret = os.environ.get('SPOT_SECRET')
uri = 'https://localhost'
token = util.prompt_for_user_token(username=user,
scope=desired_scope,
client_id=id,
client_secret=secret,
redirect_uri=uri)
I think for your redirect url spotify requires the initial http(s) part - don't forget to add it to the white-list in your Spotify for Developers app too, as otherwise you will get 'invalid-redirect-uri'.
I want to write a Python script that reads the names of the Facebook users who wrote a message on my Facebook Page.
I'm using the facebook-sdk Python library. The lines
graph = facebook.GraphAPI(page_access_token)
profile = graph.get_object(profile_id)
posts = graph.get_connections(profile['id'], 'feed')
print(posts['data'][0]['message'])
print(posts['data'][0]['from']['name'])
work fine when I use a short-lived access token retrieved by just copying it from the Graph API explorer.
But when I generate a never-expiring page access token (read here), there is an error in the last line where the Python script wants to retrieve the name. (KeyError: 'from')
So how do i set the right permissions? The access token has user_about_me, user_posts, read_page_mailboxes, manage_pages, publish_pages, public_profile permissions, but it still doesn't work. Maybe I did something wrong setting up the app I created to retrieve a new access token?
Or maybe this isn't a permissions issue after all? (See my previous question.)
You need to specify the fields you want to retrieve manually if you're using v2.4 or higher. Unfortunately this is not documented in the project you're using:
posts = graph.get_connections(profile['id'], 'feed', 'fields=id,message,from')
should work I guess according to https://github.com/pythonforfacebook/facebook-sdk/blob/master/facebook/init.py#L117
I'm currently working on a python-based app engine website and am looking to add google identity toolkit functionality but am getting stuck on the implementation of password resets and changes to email address..
Have been able to get the python quickstart example (https://developers.google.com/identity/toolkit/web/quickstart/python) working properly but even using this, I haven't been able to properly set up the password reset and email change components
I've been going through the google groups for this at https://groups.google.com/forum/#!forum/google-identity-toolkit but can't seem to be able to find detailed steps or sample code based off python
Would anybody have any ideas or can point me in the right direction? Much appreciated!
After some trial and error, I've been able to get this to work by:
creating a gitkit instance using the gitkit server config json
calling the GetOobResult function, which sends back a dict containing the reset link, among other information (This is the crux)
finally, to get the user notification to work properly you'll need to return a json dump with {'success' : true}
Here are the key lines of code I used -- should note that this doesn't include the email sending portion with the password reset link, which you have to implement separate from gitkit..
server_config_json = os.path.join(os.path.dirname(__file__), 'gitkit-server-config.json')
gitkit_instance = gitkitclient.GitkitClient.FromConfigFile(server_config_json)
output = gitkit_instance.GetOobResult(self.request.POST,self.request.remote_addr)
if output:
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps({'success': True} ))
I'm trying to figure out how to authenticate and create an entry on quickbooks online through Python. Currently, when I try to click auth link in their API Explorer, I get 404 page.
What I'm trying to do is creating invoice through Python. However, it seems like their documentation is not complete. I contacted their support, and I haven't heard from them yet.
The python-quickbooks library is probably the correct choice now, as it is a "complete rework of quickbooks-python". It has pretty comprehensive instructions on getting and using the auth keys, though I wouldn't call it "simple", since the process is by definition somewhat complex. The instructions are "for Django", but the Django-specific code simply gets parameters out of a URL string.
We're using it to great effect, because the syntax is as easy as:
auth_client = AuthClient(
client_id = CLIENT_ID # from QB website
,client_secret = CLIENT_SECRET # from QB website
,environment = 'sandbox' # or 'production'
,redirect_uri = REDIRECT_URI
)
client = QuickBooks(
auth_client = auth_client
,refresh_token = REFRESH_TOKEN
,company_id = COMPANY_ID
)
account = Account.get(qbid, qb=client) # qbid can be retrieved from the AccountList
return account.CurrentBalance
This library will get the job done https://github.com/HaPsantran/quickbooks-python
It works in JSON so you would construct the Invoice based off of docs at https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice using the JSON examples.
The library doesn't support sandbox mode** so if you are going to use the development consumer key and secret than you would change this code.
base_url_v3 = "https://quickbooks.api.intuit.com/v3"
to
base_url_v3 = "https://sandbox-quickbooks.api.intuit.com/v3"
while in that mode.
** Sandbox mode only applies currently to U.S. QBO
Having written a lot of the module #Minimul mentions — with a very helpful start by simonv3, who figured out how to get it working first and then I just built on it — I am fairly confident that this will not support the oauth workflow of getting the request token, prompting the user to authenticate out of band, and then getting and storing the access token. It presumes you already have an access token.
Simon (or another Python developer) may be able to comment on how he gets the access token with Python, and if so, it'd be great if he (or they) could add it to the module for all to enjoy.
I had this same problem. I just figured it out and posed the step-by-step process here:
python with Quickbooks Online API v3
Hope this helps.
I looked at the existing python clients for quickbooks and found them to be either outdated or not having all the features. So i created a new python client for quickbooks which can be found at https://pypi.python.org/pypi/quickbooks-py