I could get users retweets and mention, but could not figure out how to get result for one month.
https://api.twitter.com/1.1/statuses/mentions_timeline.json
And
I am using php to find the number of retweets a status has gotten.
this is my current code:
//get account info
$connection->request('GET',$connection->url('1.1/statuses/retweets'),
array('id'=> '363332903113351168'));
//get http response code for request
$response_code = $connection->response['code'];
//convert the json response to an array
$response_data = json_decode($connection->response['response'],true);
if($code != 200)
{
print"ERROR: $response_code\n";
}
print_r($response_data);
To get mention and retweets.
Can someone tell me how retweet n mention result can shown for one month
Try impliment this logic.
First to make filter by ID of tweets and next step filter by "created_at" field. After you will can retweets resalt.
Related
I have the Academic Research access to Twitter's API and have been using Tweepy to access the API. My problem is I cannot retrieve the tweets from older tweets
This is the code attempting to retrieve the tweets using the conversation_id, from 2014
# https://twitter.com/NintendoAmerica/status/535462600294035456
start_time = '2014-11-01T00:00:00Z'
end_time = '2014-12-12T00:00:00Z'
tweets = client.search_all_tweets(query = 'conversation_id:535462600294035456', max_results = 500, start_time=start_time, end_time=end_time)
and the output is:
Response(data=[<Tweet id=535465221679489024 text='#NintendoAmerica #Pokemon [this was a link I had to remove]'>], includes={}, errors=[], meta={'newest_id': '535465221679489024', 'oldest_id': '535465221679489024', 'result_count': 1})
which is only one seemingly random tweet amongst many.
However, when I tried running the same code on a more recent tweet, it retrieved all the tweets. I do not have to specify a start/end time because it's a tweet from the past 30 days.
# https://twitter.com/380kmh/status/1545477360916373504
tweets = client.search_all_tweets(query = 'conversation_id:1545477360916373504', max_results = 500)
the output was complete (shortened, I removed the tweets):
Response(data=[...], meta={'newest_id': '1546465585093087235', 'oldest_id': '1545477768229670912', 'result_count': 18})
I followed Tweepy's documentation here, using Client.search_all_tweets:
https://docs.tweepy.org/en/stable/client.html#tweepy.Client.search_all_tweets
I also tried using Postman to retrieve the tweets but it came out empty, even though I followed the documentation here:
https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all#tab0
Query: https://api.twitter.com/2/tweets/search/all?query=conversation_id%3A537923834557771776&start_time=2014-11-01T00:00:00.000Z&end_time=2014-12-18T00:00:00.000Z&tweet.fields=in_reply_to_user_id,text
Output:
{
"meta": {
"result_count": 0
}
}
What am I doing wrong?
I need to only get the followers I have not fetched before. Currently I can only get the top 200 items or given count but I don't want to get the same data more than once.
The only way I know how is to cycle through them and follow them if they haven't already been followed. I don't believe it's possible by looking at the API:
https://www.geeksforgeeks.org/python-api-followers-in-tweepy/
Make sure you have the third line for the API:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth, wait_on_rate_limit = True)
Here's my snippet for following:
followers = tweepy.Cursor(api.get_followers).items()
for follower in followers:
if follower.id not in friends:
user = api.get_user(follower.id)
follower.follow()
followers = tweepy.Cursor(api.get_followers).items()
I just discovered that .items() can be passed a number. So you could do something like:
followers = tweepy.Cursor(api.get_followers).items(50)
Additionally, looking at the API documentation, API.get_followers() method, you can also set the number of followers to go through by passing a value to the count variable.
API.get_followers(*, user_id, screen_name, cursor, count, skip_status, include_user_entities)
API.get_followers(count=50)
The followers are returned in the number that they were added.
I want to use youtube video:list api to get details of multiple videos in single request. As per the api documentation, I can send comma separated videoId list as id parameter. But what is the maximum length possible?
I know the GET request limit is dependent on both the server and the client. In my case I am making the request from server-side and not from browser. Hence the maximum length could be configured on my end. But what is the maximum length acceptable for youtube?
UPDATE: Though official documentation couldn't find, current limit is 50 ids from the tests performed as explained by Tempus. I am adding a code below with 51 different video ids (1 is commented) for those who want to check this in future.
var key = prompt("Please enter your key here");
if (!key) {
alert("No key entered");
} else {
var videoIds = ["RgKAFK5djSk",
"fRh_vgS2dFE",
"OPf0YbXqDm0",
"KYniUCGPGLs",
"e-ORhEE9VVg",
"nfWlot6h_JM",
"NUsoVlDFqZg",
"YqeW9_5kURI",
"YQHsXMglC9A",
"CevxZvSJLk8",
"09R8_2nJtjg",
"HP-MbfHFUqs",
"7PCkvCPvDXk",
"0KSOMA3QBU0",
"hT_nvWreIhg",
"kffacxfA7G4",
"DK_0jXPuIr0",
"2vjPBrBU-TM",
"lp-EO5I60KA",
"5GL9JoH4Sws",
"kOkQ4T5WO9E",
"AJtDXIazrMo",
"RBumgq5yVrA",
"pRpeEdMmmQ0",
"YBHQbu5rbdQ",
"PT2_F-1esPk",
"uelHwf8o7_U",
"KQ6zr6kCPj8",
"IcrbM1l_BoI",
"vjW8wmF5VWc",
"PIh2xe4jnpk",
"QFs3PIZb3js",
"TapXs54Ah3E",
"uxpDa-c-4Mc",
"oyEuk8j8imI",
"ebXbLfLACGM",
"kHSFpGBFGHY",
"CGyEd0aKWZE",
"rYEDA3JcQqw",
"fLexgOxsZu0",
"450p7goxZqg",
"ASO_zypdnsQ",
"t4H_Zoh7G5A",
"QK8mJJJvaes",
"QcIy9NiNbmo",
"yzTuBuRdAyA",
"L0MK7qz13bU",
"uO59tfQ2TbA",
"kkx-7fsiWgg",
"EgqUJOudrcM",
// "60ItHLz5WEA" // 51st VideoID. Uncomment it to see error
];
var url = "https://www.googleapis.com/youtube/v3/videos?part=statistics&key=" + key + "&id=" + videoIds.join(",");
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
(xmlHttp.readyState == 4) && alert("HTTP Status code: " + xmlHttp.status);
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
The answer is 50. Reason being, is that is all you will get back.
As some calls can have quite a few results depending on search criteria and available results, they have capped the "maxResults" at 50.
Acception to this is the CommentThreads which are up to 100.
This is (as you can work out) to speed page loads and call times.
EDIT:
This can be tested out HERE in the "Try api" part.
You will need to put 50 videoID's into the "id" field separated by coma's.
Then ad one more ID to get 51 and test again. You should receive a "400" response.
P.S. they do not need to be unique ID's. So have a few and then copy and paste as many times as needed ;-)
I am using twitter_timeline to get the user details.
It provides set of tweets including RTs. I am considering on retweets from all tweets.
Suppose I retweeted any tweet, which I can get using:
$tweets3 = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?trim_user=true&include_rts=true");
foreach ($tweets3 as $item)
{
$rt_reach = $item->retweet_count; //This is available
$text = $item->text; //This is available
$follower_count = $item->user->followers_count; //This is not available
echo "User location $item->user->location"; //This is not available
echo $follower_count = $item->user->screen_name; //This is not available
}
Link to document: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline
Why it does not provide last three value in above code?
Since you're using "trim_user=true", twitter strips the user record except for the user_id.
Please check trim_user parameter here.
The "trim_user" param is used by applications to stop the tweets data from getting bloated and it should be excluded if the app needs the full user record, which seems to be the case for you.
I am trying to fetch tweets from Twitter timeline using the max_id field present in next_results as demonstrated here.(Twython search API with next_results)
For most of the queries I get the desired number(500+) of tweets but for some I get less than 200 tweets.
When looking into what is returned in 'next_results I found that after returning just 100 tweets, the response has next_results field missing. There cannot be just 200 tweets for the queried topic as I am searching for this topic when it is trending and on Twitter I can see more than 200 tweets.
Is anyone else also facing this issue. Is there any workaround ?
Below is the output where in the second response the 'next_results' field is missing.
TEST_PROGRAM >> Calling twitter to get tweets for #TheWorstLieEver
{u'count': 100, u'completed_in': 0.066, u'max_id_str': u'432942833725497345', u'since_id_str': u'0', **u'next_results': u'?max_id=432540545630494719&q=%23TheWorstLieEver&count=100&include
_entities=1&result_type=mixed'**, u'refresh_url': u'?since_id=432942833725497345&q=%23TheWorstLieEver&result_type=mixed&include_entities=1', u'since_id': 0, u'query': u'%23TheWorstLieEver
', u'max_id': 432942833725497345L}
{u'count': 100, u'completed_in': 0.111, u'max_id_str': u'432540545630494719', u'since_id_str': u'0', u'refresh_url': u'?since_id=432540545630494719&q=%23TheWorstLieEver&result_type=mixe
d&include_entities=1', u'since_id': 0, u'query': u'%23TheWorstLieEver', u'max_id': 432540545630494719L}
I got the answer. If you are looking for volume, you need to use Streaming API instead. Twitter search API focuses on relevance of query and hence might not return all tweets. Twitter documentation says Before getting involved, it's important to know that the Search API is focused on relevance and not completeness. This means that some Tweets and users may be missing from search results. If you want to match for completeness you should consider using a Streaming API instead.