I am farely new to the Twitter API and I've got the following issue.
I try to send a tweet with the 'Twitter v2 API / Manage tweets / POST Create a Tweet' endpoint.
Unfortunately this results in an error '429', every time i call this endpoint (manually)
{
"title": "Too Many Requests",
"detail": "Too Many Requests",
"type": "about:blank",
"status": 429
}
The returning header shows nothing strange (from my inexperienced point of view) , see screenshot below
Headers of 429 response
Some general remarks:
I've got just 1 application in my Twitter developer account.
Within this application there is just one App.
I am the only one who generates the requests manually.
The execution is manual and all within the bounderaries of the API (200 per 15 min)
I started with the 'out the box' create_tweet.py solution (see link below), due to my misunderstanding I made several autorization request with the same twitter user, (following the link, entering the PIN) maybe that triggered some type of blockage or rejection? I regenerated all my tokens and started all over via Postman (as mentioned in the Quickstart, see link below) The error 429 is still there (both with the python script as via Postman)
Anyone got an idea? Thanks in Advance!
Links:
create_tweet.py:
https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/Manage-Tweets/create_tweet.py
Quickstart:
https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/quick-start
Related
I am trying to use the python package yagmail to send emails but am having a tough time getting authorization to work.
My issue is getting an Oauth 2 token, but there is a disconnect with yagmail, as specified in a github thread. As stated in this post, https://github.com/kootenpv/yagmail/issues/143, it appears that google does not supply the credential file in the correct format. But I tried a bunch of things and each has its own problem.
When I set up a Client ID in the Google API console, download the
json as credentials.json and let the system create the token.json,
things work to a point: I am brought through google to "pick an
account, do you want to continue" and token is created. I am able to
print labels for the gmail account. But when I issue
yag.send(to='xxx#gmail.com', subject='Testing Yagmail',
contents='Hurray, it worked!'), I get an error "TypeError:
refresh_authorization() got an unexpected keyword argument 'token'."
When I look at the token file, it does contain the key 'token' which
it should not per this github post https://github.com/kootenpv/yagmail/issues/143#issuecomment-527115298][2].
If I go into the token and edit it to reflect the the expected
contents as identified in the above link by removing keys that are
not specified and prefixing the names with 'google_', I get an error
"ValueError: Authorized user info was not in the expected format,
missing fields refresh_token, client_id, client_secret." It doesn't
seem to like the 'google_' prefix.
editing the token file as above without the 'google_' prefix seems to
get further producing a different error "An error occurred:
<HttpError 403 when requesting
https://gmail.googleapis.com/gmail/v1/users/me/labels?alt=json
returned "Request had insufficient authentication scopes"
I am stuck. Relatively new to Oauth2, but it seems others are able to use yagmail. Is there a trick I am missing? I originally posted on Github because I found that other related post, but it seems SO is more geared toward Q&A. Is there a relation betweeen Github and SO? Difference?
Thanks for any assistance,
Brian
I finally found a solution and the answer was hidden in plain sight.
First the Oauth authorization needed to be set up as outlined in this post (which is excellent): Sending email via Gmail & Python
As stated, when yagmail is run the first time the authorization process gives instructions, the final stating to "Navigate to the following URL to auth:" and asks "Enter the localhost URL you were redirected to:"
The problem is the browser window shows what appears to be an error message, a sad face with a message "This site can’t be reached, localhost refused to connect, reload", etc. I never thought this was expected behavior. The url is the one being navigated to in the error screen.
Simply stating the error should be expected, and the url needs to be copied and pasted in the post above would help a lot.
Good morning,
I want to query households (my first query and generally first experience with the Sonos API) and have authenticated successfully. I got an access token and query the Control API like this:
headers={"Content-Type" : "application/json",
"Authorization" : "Bearer " + token["access_token"]}
resp = re.get('http://api.ws.sonos.com/control/api/v1/househoulds', headers=headers)
It returns me a response with error code "503: Service unavailable":
Service Unavailable
Service Unavailable - Zero size object
The server is temporarily unable to service your request. Please try again
later.
Reference XXXXX
(I cut out the reference because I am not sure, if it contains credentials). I remember that when I intentionally changed my access token to a wrong one yesterday, I would get an error code back that I am not authorized. But now when I change it to a false one I still just get this same page back (503: Service unavailable).
Does anyone have the same problem? Might it be some security mechanism because I authorized many times in a short time or is the control API just currently down? I tried yesterday and today and don't see a blog post stating a downtime.
I see two issues with the code snippet you provided:
Issue 1: Your API URL has a typo. You used "househoulds" instead of
"households".
Issue 2: Your URL needs to use https://, not http://
If you fix those two issues and are indeed using a valid access token, your request should work.
I've been testing reading from the Graph API with an app I'm working on for a while. I've been reading events directly from their /{id} endpoints using the Python package. When I attempted this today, however, it didn't work. The response was as follows, when attempted using the Graph API Explorer.
{
"error": {
"message": "Unsupported get request. Object with ID 'XXXXXXXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "HAli25GZ3N4
"
}
}
The Explorer itself seems to know somehow that the object in question is an event, as the field options it gives in the left sidebar are all specific to Event objects. I'm aware you need to go through App Review to be able to read public Events, but I haven't needed to thus far. What's the issue?
I've also checked the changelogs, that state nothing breaking has occured today in that instance. One thing to note was that I was briefly demoted to Moderator of the Page I'm trying to read from. I've tried using my personal Access Token and that of the Page too.
I have an issue with access to Youtube Analytics API for random youtube channels.
After a successful authorization with following scopes:
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/yt-analytics.readonly
I'm saving the token and refresh token in the database. Everything works well for some time. After a while (eg. three months) when my app makes a request, Google returns 403:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
but only for Youtube Analytics API, other endpoints in Youtube Data API works fine with this token.
That happen for random accounts (channels). Owners of this channels didn't revoke access to my app, didn't change account password etc.
This issue affects about 40% of all channels in my application (the time when Youtube Analytics API stops working is different, from 1 to 6 months after obtaining OAuth2 token). Then I have to send them periodically a new authorization url.
Where is the problem?
This is how I generate an auth url and make requests:
Auth URL:
flow = client.flow_from_clientsecrets(
secret_file_path,
scope=["https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly"],
redirect_uri=redirect_url,
prompt="consent"
)
flow.params["access_type"] = "offline"
url = flow.step1_get_authorize_url(state=state)
Stats request:
auth = client.OAuth2Credentials.from_json(credentials_from_db)
http_auth = auth.authorize(httplib2.Http())
api = discovery.build("youtubeAnalytics", "v1", http=http_auth,
cache_discovery=False)
api.reports().query(
ids="channel==%s" % channel_id,
metrics="estimatedMinutesWatched",
dimensions="video",
start_date=start_date,
end_date=end_date,
max_results=20,
filters="video=={}".format(",".join(video_ids))
).execute(http=http)
I'm using google-api-python-client 1.6.5
Edit
I attached screenshot while debugging requests to google API using google-api-python-client. Here's what's going on:
Retrieving channel's base stats using Youtube Data API
Retrieving channel's advanced stats using Youtube Analytics API
My point is that, the refresh token is successfully exchanged in both cases but works only with Youtube Data API. I purposely exchange it twice. The same result is when I access only Youtube Analytics API with one successful token exchange (without calling Youtube Data API).
And the most fun part is that, this code works for some time (a couple weeks or months) and then stops :-)
Ok lets start with a little background information.
There are sevral reasons why a refresh token would stop working.
It gets to old refresh tokens expire after six months if not used.
A user can reauthecate your application and get a new refresh token both refresh tokens will work you can have a max of fifty outstanding refresh tokens then the first will stop working.
the user can revoke your access.
Wakey daylight savings time bug of 2015. (we wont talk about that)
Now none of this is the case for you. Why because the refresh token still works your just drooping a scope. Which is crazy a user cant remove your access to one scope and it wont expire one scope.
That being said i am leading towards this being a bug. I have sent an email off to someone I know who is on the Oauth team.
In the mean time. I have an idea?
What happens if you try and request a new access token using the refresh token? Could it be an issue with the access token that was returned to you?
Given that you say that the token refresh works but the API call returns error, the only thing that I suspect is some issue on the api side.
Are you making these API calls from your server? For how many users? You may be running into per IP based limits. I don't know that for sure.
I think the easiest way to find the issue will be if you can send us a few tokens that start returning error. We can lookup if the tokens became invalid or there is an issue on the API side.
You can email them to oauth-help#google.com
I have the same question as in the link below. That question remains unanswered:
Why different requests return same geolocation with google geolocation api
I have the same question, Why do I get the same google data response on every request? The data I get is always the same.
If I send the curl POST request to Google, I get the same response no matter the value in the JSON key value.
If I send POST request using Python 2.7 using requests I always to the same response no mater the value I set in my variable use for the URL POST request.
Any ideals, what key values would be needed, so I can pull the desired data. For example I want to parse the "locationAreaCode" for various area codes, and I want the request to return the "lat" and "lng" for each lookup.
Using the terminal in MAC OS:
curl -d #your_filename.json -H "Content-Type: application/json" -i https://www.googleapis.com/geolocation/v1/geolocate?key=[use your Google API key]
Note: "your_filename.json" is the literal name for the .json file.
This .json file is currently configured below(I have tried various key values):
[
"cellTowers",
[
"locationAreaCode",
415
]
]
When I use python 2.7 with the request syntax, I will get a "response 200" and I will get the exact same data returned.
I always get the same response:
Confirming Status Code is: 200
This is the POST url sent to Google
[link - had to remove since new user to stackoverflow]
Data Returned on the POST request is:
{
"location": {
"lat": 25.7459338,
"lng": -80.30449569999999
},
"accuracy": 37571.0
}
Output from python 2.7:
python API_json2-6.py
[link - had to remove since new user to stackoverflow]
Status Code is: 200
Confirming Status Code is: 200
This is the POST url sent to Google
https://www.googleapis.com/geolocation/v1/geolocate?key=[your google api KEY]&locationAreaCode=415
Data Returned on the POST request is:
{
"location": {
"lat": 25.7459338,
"lng": -80.30449569999999
},
"accuracy": 37571.0
}
Thanks!
As detailed in Geocoding Strategies, the basic architecture for a server-side geocoding application is the following:
A server based application sends an address to the server's geocoding script.
The script checks the cache to see if the address has recently been geocoded.
If it has, the script returns that geocode to the original application.
If it has not, the script sends a geocoding request to Google. Once it has a result, it caches it, and then returns the geocode to the original application.
Sometime later, the geocode is used to display data on a Google Map.
Please note also on the given quota considerations for the things to be avoided when running client-side geocode requests at periodic intervals and on caching considerations wherein The Google Maps API allows you to cache geocodes (i.e. store them on your server for a limited period). Caching can be useful if you have to repeatedly look up the same address.