Twitter API get Parameters after Oauth - python-3.x

I'm using Allauth for Twitter, works like a charm.
I have never worked with Scopes, so my question is, is there any support to get for example the twitter user stream?
Or anyone got any ideas how to get the request working?
I'm struggeling with the twitter api, it seems way more complicated then facebook or foursquare or any other api i have come across.
with facebook it's like this
return requests.get("https://graph.facebook.com/v2.3/%s&access_token=%s" % (path, access_token)).json()
Now if i send
requests.get('https://api.twitter.com/1.1/statuses/home_timeline.json&oauth_consumer_key=' +oauth_con+ 'oauth_signature_method="HMAC-SHA1"&oauth_nonce="'+now+'"&oauth_token="'+twitter+'"&oauth_timestamp="'+now+'"&oauth_version=1.1"')
I get a either a 400 error or a 404 error depending on .json? or json&.
According to the doc you have to have "" around every parameter. Didn't help.

Related

Instagram Hashtag Search API returns error message "user_id is required" although I have provided it

I am trying to get data about media from my IG Business account with a specific hashtag.
I used Graph API Explorer and tried with
/{hashtag_id}?user_id={instagram_business_id}&fields=recent_media
but I got an error "(#100) The parameter user_id is required."
Does anybody know what may be the problem and how to solve it?
The API URL is incorrect, your URL should look like this:
/{hashtag_id}/recent_media?user_id={instagram_business_id}&fields=id,caption,media_url...

Spotify API Token Scope Issue

I have been at this for sometime now and wanted to see if anyone had and idea of what I could be doing wrong. What I am trying to do is add a song to a playlist using the provided Spotify Web APIs. According to the documentation on this https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/ I need to establish the scope of the user.
"adding tracks to the current user’s private playlist (including collaborative playlists) requires the playlist-modify-private scope" I have created the playlist as collaborative and I am using the login credentials of my personal account to reach this playlist I created. all this is under the same login.
What I am finding is that my scope is not getting added to my token on my call for my token causes a 403 error when I try to add the song.
Here is what that call looks like
https://accounts.spotify.com/authorize/?client_id=mynumber&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
here are the docs on using authorization to get the correct token.
https://accounts.spotify.com/authorize/?client_id=894400c20b884591a05a8f2432cca4f0&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
further more if I go into the dev support here
https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/
and click the green try button and then request a new token it works.
Bottom line some how my request is not taking my scope request. Any Ideas?
Thanks
To get the token with a specific scope you need to go to the authorize endpoint and get the code. The code is what you want to get to be able http post to the endpoint https://accounts.spotify.com/api/token and get a token with your desired scopes. You can simply get the code by pasting a url like this in your browser...
https://accounts.spotify.com/authorize?client_id=<client_id>&response_type=code&scope=streaming%20user-read-email%20user-read-private&redirect_uri=<redirect_uri>
Only add %20 in between scopes if you have multiple ones
You will then be sent to spotify's website and they'll verify you want to do this. Once you verify it your browser will redirect you to what you set the redirect_uri to be in the url above. At the end of the url that you are sent to, you should be able to see the parameter name code with the code value assigned to it. You then get that code and put it in your http post body params to the https://accounts.spotify.com/api/token endpoint. Make sure you accurately follow the query params requirements in your post method.
An example of the post in python using the requests library:
authorization = requests.post(
"https://accounts.spotify.com/api/token",
auth=(client_id, client_secret),
data={
"grant_type": "authorization_code",
"code": <code>,
"redirect_uri": <redirect_uri>
},
)
authorization_JSON = authorization.json()
return authorization_JSON["access_token"]
In the end you should get a json that shows the scopes you set a long with a refresh the token later on to make more requests.
I know this answer is quite late but I was experiencing the same issue as well which is how I came across this question. I hope this helps anyone that sees this at a later date.
Source: https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow

Instagram api not-working

I trying to use instagtram api. But endpoints: comments and likes not working.
https://www.instagram.com/developer/endpoints/comments/
But if I try to get comments - Data is empty.
What`s wrong?
Instagram API after Jun'16 is so unusable.
Try fetch this https://www.instagram.com/query/?q=ig_shortcode(BK07W-Xhq6S){comments.last(20){count,nodes{id,created_at,text,user{id,username,full_name}},page_info}} and you receive JSON with comments data.

Twitter API 1.1 OAuth Get Use Data

I read this tutorial to implement twitter oauth in nodejs (for "login with twitter" purpose) -
http://codetheory.in/how-to-use-twitter-oauth-with-node-oauth-in-your-node-js-express-application/
The last piece of code has this variable called results which is supposed to hold the user data sent back by twitter, but for me it only contains screen_name and user_id which is not enough. I need much more data like profile image, etc.
So I looked at the twitter documentation -
https://dev.twitter.com/docs/api/1/get/users/show
The sample URL seems to work fine -
https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true
But recently I read twitter will shut down API 1 soon and replace it with API 1.1
So I tried the 1.1 API -
https://dev.twitter.com/docs/api/1.1/get/users/show
The sample URL does not work -
https://api.twitter.com/1.1/users/show.json?screen_name=rsarver
Gives error -
{"errors":[{"message":"Bad Authentication data","code":215}]}
What am I doing wrong ? How do I get user info properly from twitter and hopefully in my Node.js code that uses this module - https://github.com/ciaranj/node-oauth ?
Thanks in advance!
API v1.1 endpoints require OAuth authentication.
You might look at a different oauth module: ntwitter

web site scraping through Jsoup

I have spent few hours on signing in to web site by using jsoup. But it always gives same login page. To clarify the issue I tried with facebook site. It also gives same result.
Below I mentioned my code
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com","pass","xyz")
.userAgent("Mozilla").post();
System.out.println(doc);
can anybody point me where I made a mistake and how can i fix this issue?
In data portion "email" and "pass" are input field id of facebook login page.
Thank you.
Try this:
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com")
.data("pass","xyz")
.userAgent("Mozilla")
.post();
Anyway, Jsoup is not bad at all, you only need how to use it properly, but also you need to keep in mind that Facebook is expecting a lot more parameters to make a successfull login via POST emulating a web page navigation.
By example:
charset_test
default_persistent
lgnjs
lgnrnd
locale
lsd
pass
persistent
timezone
If you need to authenticate and get proper data I suggest that you must give a try to a Facebook SDK for Android:
https://github.com/facebook/facebook-android-sdk/

Resources