Closed zoinkydoink closed 1 year ago
For fetching simply, the tweets of a user, you don't need cookies.
Cookies are required only for advanced data fetching such as followers, likes, retweets and advanced tweet search.
Please refer to official docs: https://rishikant181.github.io/Rettiwt-API/
my apologies, i had looked at the docs and came up with the following, did i even call the library and query correctly?
import { Rettiwt } from 'rettiwt-api'
import { TweetFilter } from 'rettiwt-api/src/models/args/TweetFilter'
function getTweets(): void {
const rettiwt = Rettiwt();
const query = {"fromUsers":['elon_musk']};
const filter = new TweetFilter(query);
//const tweets = rettiwt.tweets.getTweets(filter);
}
getTweets();
But now I am getting error
D:\temp\retrieveTweets\node_modules\rettiwt-api\src\models\args\TweetFilter.ts:2 import { IsArray, IsBoolean, IsNumberString, IsString, IsOptional, IsDateString, validateSync } from 'class-validator'; ^^^^^^
SyntaxError: Cannot use import statement outside a module at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1176:20) at Module._compile (node:internal/modules/cjs/loader:1218:27) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Object.require.extensions.
[as .ts] (D:\temp\retrieveTweets\node_modules\ts-node\src\index.ts:1608:43) at Module.load (node:internal/modules/cjs/loader:1117:32) at Function.Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (D:\temp\retrieveTweets\src\main.ts:2:1) [nodemon] app crashed - waiting for file changes before starting...
There are actually multiple issues with this code. Let me point it out.
const rettiwt = new Rettiwt({
auth_token: "received_auth_token",
ct0: "received_ct0_token",
kdt: "received_kdt_token",
twid: "received_twid_token"
});
If you don't want to provide cookies, use this method instead
It seems (could be wrong) that UserService (where getUserTweets) lives requires an AuthService to be passed into its contructor which would mean I have to provide some sort of authentication token? Are you able to provide a simple sample/example where I have the @ of a user and I am able to get the tweets for that user without a authenticatio/cookie?
Thank you, and again for really barrage of questions.
You don't need to. When you create a new instance using Rettiwt() function, that AuthService instance is automatically created.
As for example, here is the sample code:
import { Rettiwt } from 'rettiwt-api';
async function getTweets() {
const rettiwt = Rettiwt();
// Getting the details of the user, from this, rest id will be used for fetching tweets
const user = await rettiwt.users.getUserDetails('elonmusk');
// Getting the tweets of the user using his rest id
const tweets = await rettiwt.users.getUserTweets(user.id);
}
that example worked perfectly, thank you.
More questions.
Is there a way I can get NON reply tweets? other than get all than filter for the ones that have replyTo
as undefined
.
It would be nice if.getUserTweets()
included a flag to exclude replies,
If i have to filter the data, since its CursoredData type, how do i just get the none reply out of the list? (i couldnt figure it out, my apologies)
Thank you again
Excluding replies is not applicable for the method getUserTweets, since the endpoint that it calls does not provide that feature. If however, you really want to exclude replies, you may use this method with the flag 'links' set to false. However, this method requires you to use cookies!
I like to get all tweets for a given @username does that mean i have to hve a twitter account and fill the cookie info to achieve this, or can these be p art of the guest fetch. Also are there examples of all different calls.
I simply want to be able to fetch all tweets for a given @, please and thank you