Simple jQuery getJSON Call to Twitter - javascript

I have read many Twitter & jQuery questions on here but none seem to answer my question. I am simply trying to grab 5 "tweets" from a public user. I am not doing anything with the data at this step, but my callback function never fires.
$.getJSON("https://api.twitter.com/1.1/statuses/user_timeline.json?callback=?",
{
screen_name: 'dojo',
count: '5'
},
function (data) {
alert("IT WORKED!");
});
Here is the same code on jsFiddle
Thank you for your help

That isn't going to work because Twitter has now required that you authenticate in order to fetch tweets for a given user.
Reference: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline Look at 'Authentication' info.
You'll want to use a library to help get an oauth signature and make the request.

Related

Could not authenticate you - twitter api v1.1

I am trying to use the Twitter API to tweet, retweet, and upload images, while tweet works as intended, upload media don't work. more information below
packages i use :
node-fetch
deepmerge - to merge the given options
oauth-1.0a
crypto
the error appears at all the fetch request related to this function
Error:
{ errors: [ { code: 32, message: 'Could not authenticate you.' } ] }
I know whats the error is about, just asking this as I am confused why this would appear only in this function,as the auth info is correct and the same function used to create the headers work in another function
some important functions and related : https://hastebin.com/eyepikidax.kotlin
the code affected : https://hastebin.com/inehomodag.js
tweet function : (the working function) : https://hastebin.com/xatebakahe.properties
even though the tweet works with the same function _makeRequest(custom function) uploadmedia dont
uploadmedia is same as tweet but with extra steps like uploading media
i logged the headers provided by _makeRequest for the tweet function and the upload function
headers: https://hastebin.com/xojotupine.rust
it seems in the uploadmedia function the headers became invalid but in the tweet function they are valid
The issue was with the authorization headers, I had to generate them for each request.It was easy as creating a wrapper function that will take the request details (the needed ones) and output the headers
I have a Twitter API library written in typescript (unmaintained for now :/ )
That uses this, don't suggest completely using that, just take what you need from it
Code Related
^^
Above Links to - https://github.com/typicalninja493/tweets.ts/blob/master/src/rest/bucket.ts#L200

Node.js Twit Twitter Module

I'm having a little problem figuring out how to follow, like retweet someone's tweet.
As you can probably see I can get all tweet's mentioning justinbieber but i want to be able to put somecode in the function to either retweet or like the status or even follow the user that tweeted it.
If you managed to understand all of that jumble I'd appreciate the help!
What stream.on(...) does is call the function in the second parameter every time a tweet comes up, and it passes the tweet itself as a parameter. So every action you want to do with that tweet, you need to do it in the function.
To see all information on the tweet object you can go on the Twitter API page. You have access to all of this in your anonymous function !
For retweeting every tweet :
...
stream.on('tweet', function(tweet) {
T.post('statuses/retweet/:id', { id: tweet.id_str }, function (err, data, response) {
console.log(data)
})
})
Syntax taken from twit module documentation
First time answering, I hope this helps.

Facebook javascript API get users photos one at the time

Hello i am trying to get the users tagged photos one at the time with javascript.
Here is how i call it:
FB.api('/me?fields=name,picture.type(large),photos.limit(2).type(tagged)', function(response) {
play(response.name, response.picture.data.url, response.photos.data.source);
....
And how i use them:
use: {url: "some url....", params: ['name','fb','photo1', 'photo2']},
The thing is that when i call this i get "Cannot read property 'data' of undefined "
on the photos.limit(2).type(tagged)
The other things work great. Name and profile pic.
Any ideas?
Perhaps i need to sort the results from photos.limit(2).type(tagged) or something but i have no clue o how to do that...
Any help will be awesome.
Thanx
Sounds like you aren't getting any data from the photos endpoint.
Ensure that you have user_photos permission in
FB.login(function(response) {
// handle the response
}, {scope: 'user_photos'});

Get friends read articles with Facebook JS API

i'd like to know how to fetch articles that friends have read from a Facebook app. I use the following query to get articles that I have read:
/me/news.reads
But i want all the articles that friends have read, is that possible?
It is not an apt solution but you can do is loop through facebook id's of your friends and for each friend's Id get all the news read as /$friend_id/news:reads
I dont think there is any direct api function to get action performed by friends.
Try this
FB.api('/me/friends', { 'fields' : 'name,news.reads.limit(10)' }, function (data) {
// if(!data || data.error) { }
// console.log(data);
});
You can omit the limit if you like, or add more fields. Of course this would also work as a GET request to: http://graph.facebook.com/me/friends?fields=name,news.reads.limit(10)&access_token=XXXX

JavaScript OAuth sign in with Twitter

I have to integrate Sign-in-with Twitter in my app as below.
https://dev.twitter.com/docs/auth/sign-twitter
It is browser based app developed in JavaScript
I have been refering google code java script OAuth, but im confused how to use oauth/authenticate and how to get the oauth_token
Can any one please help me out with some samples ?
Problem with this is that anyone who views your page can also now view your consumer key and secret which must be kept private.
Now, someone could write an app that uses your app credentials and do naughty and bad things to the point that twitter and users ban you, and there isnt anything you can do.
Twitter do state that every possible effort must be made to keep these values private to avoid this happening
Unfortunately, there is currently no way to use oAuth in Browser based JavaScript securely.
Check out the Twitter #Anywhere JSDK authComplete and signOut events and callbacks at https://dev.twitter.com/docs/anywhere/welcome#login-signup
twttr.anywhere(function (T) {
T.bind("authComplete", function (e, user) {
// triggered when auth completed successfully
});
T.bind("signOut", function (e) {
// triggered when user logs out
});
});
Use below code in consumer.js and select example provider in index.html drop down list
consumer.example =
{ consumerKey : "your_app_key"
, consumerSecret: "your_app_secret"
, serviceProvider:
{ signatureMethod : "HMAC-SHA1"
, requestTokenURL : "https://twitter.com/oauth/request_token"
, userAuthorizationURL: "https://twitter.com/oauth/authorize"
, accessTokenURL : "https://twitter.com/oauth/access_token"
, echoURL : "http://localhost/oauth-provider/echo"
}
};
Since I was searching for the same thing, trying not to use a custom PHP solution, I came across this very simple integration at http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm which uses a PHP proxy that accepts whatever twitter api call you'd like to retrieve from your javascript ..
I'm definitely taking a look at it

Categories