I'm having problems to find a simple python twitter oauth example which shows how to post a user status on Twitter. Could you help me?
Check out Mike Knapp's library on GitHub.
Nice and simple, no install needed.
Here's an example that will get you authed with Twitter using rauth.
After that point all you'd have to do to update the authenticated user's status is:
r = session.post('statuses/update.json',
data={'status': 'Updating my status from the cmd line.'})
print r.json()
(You only need to care about the code up until you retrieve your authenticated session object, i.e. line 20.)
Hope this helps!
Edit
You will need to get your own consumer_key and consumer_secret for this to work because the rauth demo app does not have write permissions, for obvious reasons. So you'll end up with this response if you try to run the modified script without updating the credentials:
{u'request': u'/1/statuses/update.json', u'error': u'Read-only application cannot POST'}
Ensure your application is allowed to write and it should work as expected.
Take a look on tweepy: http://code.google.com/p/tweepy/
Have you checked out http://github.com/simplegeo/python-oauth2 ?
Matthew A. Russell has written an excellent book on this, Mining the social web. Take a look at his excample source for OAuth to twitter. The code is available here, and i recommend his book also, covering not only twitter, but facebook and linkedin aswell.
The code is found here: OAuth to twitter and collect friends id's
Good Luck
Here is a simple twitter oauth example I wrote as a blog sometime ago. Hope this helps.
If you're refering to http://code.google.com/p/python-twitter/ ..
On that page it is documented as
api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token',
access_token_secret='access_token_secret')
To see if your credentials
are successful:
print api.VerifyCredentials() {"id": 16133, "location": "Philadelphia", "name": "bear"}
That works. Ofcourse, your consumer key should never be human-readable in your application. But it would work even if it was.
*-pike
I've written an extremely simple twitter client (which is just for tweeting).
The source isn't the cleanest around, but the entire thing (including UI) is under 200 lines, so you should be able to extract anything you need from it:
Related
Twitter API v2.0 added a conversation_id which supposedly enables easier access to an entire Twitter thread. Previously this kind of work was done by accessing the original tweet and then keeping track of the in_reply_to_status_id field. This is easy for replies to the original tweet, but is more cumbersome for replies to replies.
I suspect I'm missing something simple and appreciate any help. The API documentation says the conversation_id will match the tweet_id of the tweet which started the original conversation. After applying my tokens, the search code is:
replies=[]
for tweet in tweepy.Cursor(api.search_tweets,q='conversation_id:<1565355188004741120>',timeout=999999).items(1000):
replies.append(tweet)
However, the list replies returns empty. I know that conversation_id is valid because I've access the first level replies via legacy code. Any insight to using the conversation_id field is appreciated. There's surprisingly little information out there on its use. Thank you!
SOLUTION
The issue was api v1.0 vs 2.0. The following works:
replies=[]
for tweet in tweepy.Paginator(client.search_recent_tweets, query='conversation_id:1565355188004741120'):
replies.append(tweet)
i want to play with the InstagramAPI and write some code for like getting a list of my follower and something like that. I am really new to that topic.
What is the best way to do this? Is there a Python-Lib for handle those json request or should I send them directly to the (new? graphAPI, displayAPI) InstagramAPI?
Appreciate every advice I can get. Thanks :)
LevPasha's Instagram-API-python, instabot, and many other API's are no longer functional as of Oct 24, 2020 after Facebook deprecated the legacy API and now has a new, authentication-required, API. It now requires registering your app with Facebook to be able to get access to many of the API features (via oembed) that were previously available without any authentication.
See https://developers.facebook.com/docs/instagram/oembed/ for more details on the new implementation and how to migrate.
You should still be able to get a list of your followers, etc. via the new oEmbed API and python--it will require registering the app, making a call to the new GET API with your authentication key via the python requests package, and then processing the result.
There is one library called instabot. This useful library has all the necessary functions/methods to interact with your insta account. Read its documentation here.
The pip installation is: pip install instabot
To get started with, lets say you want to simply login to your account.
from instabot import Bot
bot = Bot()
bot.login(username="YOUR USERNAME", password="YOUR PASSWORD")
To get the list of your followers,
my_followers = bot.followers()
If you want to upload a photo or get your posts,
bot.upload_photo(image, caption="blah blah blah") #the image variable here is a path to that image
all_posts = bot.get_your_medias() #this will return all of your medias of the account
#to get the info of each media, use
for post in all_posts:
print(bot.get_media_info(post))
and there are many other functions/methods available in this library.
It actually very fun to interact with instagram using python. You will have a great time. Enjoy :)
You can use https://github.com/LevPasha/Instagram-API-python to call Instagram APIs
and also if you want to call API directly You can use the requests package.
It also supports graphql APIs.
Here you can see an example:
https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad
It seems like in 2022 this is the only active working and maintained python solution:
https://github.com/adw0rd/instagrapi
I just got started programming a year ago (on and off) and I am trying to save an attachment to a folder offline from my personal GMAIL account.
I was advised to use :
https://developers.google.com/gmail/api/quickstart/python
I set up the
I authenticated the my account and now am trying to get comfortable with this tool.
There are some initial questions that I have
What is User ID ?
is this my email ( tttt#xxxx.xxxx)
or someone else's email (ppppp#yyyy.yyy)
How do I get a email ID's ?
These questions stem from ...
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
from the page :
https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
Again I am just learning from a beginner place..
Thanks
Just use "me" as the userId as it says in the doc.
To get a messageId first you have to search (list) messages, using something like:
resp = gmail.users().messages().list(userId="me", q="has:attachment subject:'foo bar' before:"2014-01-05").execute()
you can then iterate through the 'messages' in that resp and
gmail.users().messages().get(userId="me", id=message['id']).execute()
The Gmail API guides are quite helpful, take a look at them, for example:
https://developers.google.com/gmail/api/guides/filtering
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
When I try hitting their API I get hit with an error for Authentication. I'm not using this for an application, but just writing a few scripts to play around.
r = requests.get('https://api.twitter.com/1.1/users/show.json?screen_name=dhh')
print r.text
Returns
{"errors":[{"message":"Bad Authentication data","code":215}]}
Can someone explain how I can fix this?
Please take a look here https://dev.twitter.com/docs/auth
You must be authenticated at first to make such request per requirements here https://dev.twitter.com/docs/api/1.1/get/users/show
You can use this library http://code.google.com/p/python-twitter/ for your requests