josuebrunel / yahoo-oauth Goto Github PK
View Code? Open in Web Editor NEWYahoo OAuth Library
Home Page: http://yahoo-oauth.readthedocs.org/en/latest/
License: MIT License
Yahoo OAuth Library
Home Page: http://yahoo-oauth.readthedocs.org/en/latest/
License: MIT License
Hey Josue thanks for this lib, saved me some time !
Maybe somebody's going to need some examples how to get yahoo gemini reports
Here's what worked for me
import urllib
import json
import time
from yahoo_oauth import OAuth2
oauth = OAuth2(None, None, from_file='credentials.json')
if not oauth.token_is_valid():
oauth.refresh_access_token()
# get all accounts
response = oauth.session.get("https://api.admanager.yahoo.com/v1/rest/advertiser/")
data = response.content
print data
jdata = json.loads(data)
for j in jdata['response']:
print "{} {}".format(j['id'], j['advertiserName'])
# get advertiser data
advertiser_id = 12345678
report_date_from = "2016-08-28"
report_date_to = "2016-08-28"
payload = {"cube": "performance_stats",
"fields": [
{"field": "Day"},
{"field": "Impressions"},
{"field": "Conversions"},
{"field": "Spend"},
{"field": "Campaign ID"}
],
"filters": [
{"field": "Advertiser ID", "operator": "=", "value": advertiser_id},
{"field": "Day", "operator": "between", "from": report_date_from, "to": report_date_to}
]}
response = oauth.session.post("https://api.admanager.yahoo.com/v1/rest/reports/custom?reportFormat=json", json=payload)
print response.content
jdata = json.loads(response.content)
job_id = jdata['response']['jobId']
# you will need to add some loop and waits before the report is ready
time.sleep(60)
url = "https://api.admanager.yahoo.com/v1/rest/reports/custom/{}?advertiserId={}".format(job_id, advertiser_id)
response = oauth.session.get(url)
print response.content
# report will be returned as url
rdata = json.loads(response.content)
if 'status' in rdata['response'] and rdata['response']['status'] == 'completed':
report = urllib.urlopen(rdata['response']['jobResponse']).read()
print report
>>> oauth = OAuth1(data['consumer_key'],data['consumer_secret'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/josue/Dropbox/Workspace/projects/yahoo-oauth/yahoo_oauth/yahoo_oauth.py", line 242, in __init__
super(OAuth1, self).__init__('oauth1', consumer_key, consumer_secret, **kwargs)
File "/Users/josue/Dropbox/Workspace/projects/yahoo-oauth/yahoo_oauth/yahoo_oauth.py", line 117, in __init__
json_data.update(self.handler())
UnboundLocalError: local variable 'json_data' referenced before assignment
>>>
It's important to save the _xoauth_yahoo_guid_ in the credentials file. it may become very handy
How to use this library (non interactively)when having access_token
and refresh_token
?
I obtained these using this flow: https://developer.yahoo.com/oauth2/guide/flows_authcode/
I need this to use this library: https://github.com/spilchen/yahoo_fantasy_api/
I have copied my consumer_key and consumer_secret into a json file and run the script:
from yahoo_oauth import OAuth2
oauth = OAuth2(None, None, from_file='oauth2.json')
My browser goes to the authorization page: "By agreeing, you will allow my_app to access: I agree to the Yahoo OpenID and OAuth terms"
I click "Agree", but then I get another page:
"Uh-oh! Looks as if something went wrong. Please try again later."
Any ideas? Thanks!
hello, this is the best python lib i have found to access yahoo oauth2.
i have get access token using this lib. but when i tried to send request to yahoo gemini api, i always got an 401 Response
here is the output:
[2015-12-16 10:55:11,472 DEBUG] [yahoo_oauth.yahoo_oauth.__init__] Checking
[2015-12-16 10:55:11,477 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] ELAPSED TIME : 164795.42615
[2015-12-16 10:55:11,477 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] TOKEN HAS EXPIRED
[2015-12-16 10:55:11,478 DEBUG] [yahoo_oauth.yahoo_oauth.refresh_access_token] REFRESHING TOKEN
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.login.yahoo.com
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
[2015-12-16 10:55:13,310 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] ELAPSED TIME : 1.83199310303
[2015-12-16 10:55:13,311 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] TOKEN IS STILL VALID
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.admanager.yahoo.com
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
<Response [401]>
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.admanager.yahoo.com
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
<Response [401]>
None
here is my code:
from yahoo_oauth import OAuth2
import requests
def get_simple_report(min_date, max_date):
yahoo_oauth = OAuth2(None, None, from_file='./config/yahooads.ini')
if not yahoo_oauth.token_is_valid():
yahoo_oauth.refresh_access_token()
access_token = yahoo_oauth.access_token
advertiser_id = 1151514
# get campaign list
campaign_end_point = "https://api.admanager.yahoo.com/v1/rest/campaign/"
payload_dict = {
"advertiserId":advertiser_id,
"mr":2
}
header = {'Authorization': 'Bearer ' + access_token,'Accept': 'application/json','Content-Type': 'application/json'}
response = requests.get(campaign_end_point, data=payload_dict, headers = header)
print response
response = yahoo_oauth.session.put(campaign_end_point, params=payload_dict)
print response
i also tried rauth but got the same error.
could you pls help me with it? thanks
Hi, thanks for your work on this project.
I'm having an issue with authorisation of my yahoo app. Specifically, I am given the authorisation url, and I enter the code to connect and I am getting the following traceback:
File "/home/jerry/.local/share/virtualenvs/In-it-to-Winnik-V2oo3_u6/lib/python3.8/site-packages/yahoo_oauth/yahoo_oauth.py", line 229, in __init__
super(OAuth2, self).__init__('oauth2', consumer_key, consumer_secret, **kwargs)
File "/home/jerry/.local/share/virtualenvs/In-it-to-Winnik-V2oo3_u6/lib/python3.8/site-packages/yahoo_oauth/yahoo_oauth.py", line 89, in __init__
data.update(self.handler())
File "/home/jerry/.local/share/virtualenvs/In-it-to-Winnik-V2oo3_u6/lib/python3.8/site-packages/yahoo_oauth/yahoo_oauth.py", line 143, in handler
credentials.update(self.oauth2_access_parser(raw_access))
File "/home/jerry/.local/share/virtualenvs/In-it-to-Winnik-V2oo3_u6/lib/python3.8/site-packages/yahoo_oauth/yahoo_oauth.py", line 165, in oauth2_access_parser
self.guid = parsed_access['xoauth_yahoo_guid']
KeyError: 'xoauth_yahoo_guid'
The weird thing is that authorizing works perfectly fine with a yahoo app that I set up 2 months ago, but it refuses to work with any new apps that I have created today. Thanks again for your help.
Currently, the authentication details are saved to a file regardless of where they are provided from:
https://github.com/josuebrunel/yahoo-oauth/blob/master/yahoo_oauth/oauth.py#L99-L101
yahoo-oauth/yahoo_oauth/utils.py
Lines 36 to 41 in a1ec871
I have use case in my bot where I am storing these details in a RDB so I do not need this file. Would be great if this could be made optional via a flag or something like that.
Yahoo Fantasy API has a rate limit of 2,000 unsigned API calls per hour and 20,000 signed calls per hour. It might be something on my end, but the oauth.session.get() doesn't seem to be sending signed requests. I've tested on single-calls and get a Response 999 (rate limit) error about very 15 minutes which amounts to between 450-550 calls. This rate is roughly 2,000/hr.
It seems like the credentials file might need an 'id_token' field (see the OAuth 2.0 Authorization Endpoint section of the Yahoo Dev documents and this part detailing the id_token. I'm not certain about this though because the Yahoo Fantasy Sports guide has sample PHP code that creates a "_make_signed_request()" function that creates/uses a HMAC-SHA1 signature. Maybe you need both? I'm not totally sure.
I try to run it on Ubuntu1604 towards Yahoo developer api, .https://developer.yahoo.com/oauth/guide/oauth-refreshaccesstoken.html
Everything works fine until it should refresh accesstoken when I get the error below.
I have tested to manually refresh with the help of Postman client and that works fine testing with the same credientals.
Any idea of what I can do to get it working ?
Below I test in Ubuntu from python terminal.
>>> oauth.refresh_access_token()
[2016-08-30 21:48:01,388 DEBUG] [yahoo_oauth.yahoo_oauth.refresh_access_token] REFRESHING TOKEN
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xx/.local/lib/python2.7/site-packages/yahoo_oauth/yahoo_oauth.py", line 186, in refresh_access_token
self.access_token, self.access_token_secret = self.oauth.get_access_token(self.access_token, self.access_token_secret, params={"oauth_session_handle": self.session_handle})
File "/home/xx/.local/lib/python2.7/site-packages/rauth/service.py", line 332, in get_access_token
process_token_request(r, decoder, key_token, key_token_secret)
File "/home/xx/.local/lib/python2.7/site-packages/rauth/service.py", line 24, in process_token_request
raise KeyError(PROCESS_TOKEN_ERROR.format(key=bad_key, raw=r.content))
KeyError: 'Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: oauth_problem=signature_invalid'
>>>
Thanks for the package. I am trying to get fantasy sport data from Yahoo's API. When I try a public request (like getting the player ranking), it works and I seem to be authentified. When I try running a private request (requires https, like getting the transactions of a particular league) it fails and returns an xml response which includes (I use oauth.session.get()
):
Authentication Error. The table fantasysports.leagues.transactions requires
a higher security level than is provided, you provided ANY but at least USER is expected
Even though the message is very straghtforward, I cannot figure out what I am missing. Either I don't know how to use the package, or there is a connection problem somewhere. I go through the whole authentication process smoothly (consumer key, consumer secret, getting the PIN) and my access_token is considered valid when calling token_is_valid()
. Is the package only good for public requests over http? I don't know what I am missing.
I have tried:
OAuth1
and OAuth2
Thanks
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/josue/Dropbox/Workspace/projects/yahoo-oauth/yahoo_oauth/yahoo_oauth.py", line 244, in __init__
super(OAuth1, self).__init__('oauth1', consumer_key, consumer_secret, **kwargs)
File "/Users/josue/Dropbox/Workspace/projects/yahoo-oauth/yahoo_oauth/yahoo_oauth.py", line 127, in __init__
json_write_data(json_data, self.from_file)
AttributeError: 'OAuth1' object has no attribute 'from_file'
I am having issues in getting the refresh token. Below is error
callback_uri oob
raw_access <Response [400]>
ac_tkn {u'error_description': u'Failed to decode/encode refresh token', u'error': u'INVALID_REFRESH_TOKEN'}
self.access_token = parsed_access['access_token']
KeyError: 'access_toke
Thanks for a great library.
I have a process which is very long running, and I am having trouble with auth token expiring. This is despite my calling the refresh_token method.
I think I may have found the problem.
In the constructor the following is called:
# Getting session if self.oauth_version == 'oauth1': self.session = self.oauth.get_session((self.access_token, self.access_token_secret)) else: self.session = self.oauth.get_session(token=self.access_token)
However, I don't think that session variable is getting updated with the new access token.
Does this make sense?
Thanks,
Craig
Create the setup.py file
$ pip freeze
rauth==0.7.1
requests==2.7.0
wsgiref==0.1.2
yahoo-oauth==0.1.2
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yahoo_oauth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named yahoo_oauth
>>> import yahoo-oauth
File "<stdin>", line 1
import yahoo-oauth
^
SyntaxError: invalid syntax
>>>
Hope that it will be above 80% even though i'm sure it won't be ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.