Java Twitter Bot tweets to another account but using my accessToken? - java

I wrote this simple code that works just fine :
//access the twitter API using your twitter4j.properties file
Twitter twitter = TwitterFactory.getSingleton();
//create a new search
Query query = new Query("\"your welcome\"");
//get the results from that search
QueryResult result = twitter.search(query);
//get the first tweet from those results
Status tweetResult = result.getTweets().get(0);
//reply to that tweet
StatusUpdate statusUpdate = new StatusUpdate(".#" + tweetResult.getUser().getScreenName() +" I believe you meant \"you're\" here?");
statusUpdate.inReplyToStatusId(tweetResult.getId());
Status status = twitter.updateStatus(statusUpdate);
The problem is, even using my own parametres (Acessstoken, Consumerkey,,) that I generated manually from app.twitter.com, the code still sends the tweet to this account : Twit4j . it seems that too many had tweeted through it too!
twitter4j.proprieties is set up correctly
libs are correctly integrated
anyone knows what could be wrong ?

The Problem were (I guess) in the class name! the package name+ my class name are "Twitter" and the Object name from the Twitter4j is "Twitter" too! think the IDE got confused maybe ?
anyway now it works just fine !

Related

Facebook's Graph API is showing much less posts for a page's feed

I am making a Java application for browsing newer and older posts from a Facebook public page.
I have the following code for retrieving the complete feed of posts:
String id = "<my app id>";
String secret = "<my app secret>";
String accessToken = "<my app access token>";
String pageId = "<my page id>";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setRestBaseURL("https://graph.facebook.com/v2.8/");
Facebook fb = new FacebookFactory(cb.build()).getInstance();
fb.setOAuthAppId(id, secret);
fb.setOAuthAccessToken(new AccessToken(accessToken));
ResponseList<Post> posts = fb.getFeed(pageId, (new Reading()).limit(100).includeHidden(true));
Set<String> postIds = new LinkedHashSet<>();
do {
for (Post p : posts) {
postIds.add(p.getId());
}
posts = fb.fetchNext(posts.getPaging());
}
while (posts != null && !posts.isEmpty());
System.out.println("Number of posts: " + postIds.size());
A few months ago (november-december), using this code for a specific page always got me a list with 15000+ posts. A few days ago, without making any modification, I only got 3000+ posts. I have seen similar results with other pages. However, using an older file with the 15000+ post ids made some time ago I determined that many of the posts that weren't showing in the smaller feed still exist and can be accessed using the Graph API.
Why aren't many posts (12000+ for that specific case) showing up anymore? Is it a bug in the Graph API? Is there another way to retrieve the complete feed of posts?
Note: I am using Facebook4j 2.4.8.

get all issues stored in jira

hi i want to get all issues stored in jira from java using jql or any othere way.
i try to use this code:
for(String name:getProjectsNames()){
String jqlRequest = "project = \""+name+"\"";
SearchResult result = restClient.getSearchClient().searchJql(
jqlRequest, 10000,0, pm);
final Iterable<BasicIssue> issues = result.getIssues();
for (BasicIssue is : issues) {
Issue issue = restClient.getIssueClient().getIssue(is.getKey(), pm);
...........
}
it give me the result but it take a very long time.
is there a query or a rest API URL or any other way that give me all issues?
please help me
The JIRA REST API will give you all the info from each issue at a rate of a few issues/second. The Inquisitor add-on at https://marketplace.atlassian.com/plugins/com.citrix.jira.inquisitor will give you thousands of issues per second but only the standard JIRA fields.
There is one other way. There is one table in JIRA database named "dbo.jiraissue". If you have access to that database then you can fetch all the ids of all issues. After fetching this data you can send this REST request "**localhost/rest/api/2/issue/issue_id" and get JSON response. Of course you have to write some code for this but this is one way I know to get all issues.

Filtered the last user tweets with TwitterStream

I have created a twitterStream in twitter4j java Api, with which I want to track down user's status. I got a list of users which is actually the followIDs. In listener actually I download user's status images. I save my images with the following name:
String ImageUniqueFileName = status.getUser().getId()+"_id_"+CreateUniqueFileName();
ImageUniqueFileName = ImageUniqueFileName + ".jpg";
I ve noticed that in saved images, I got several user ids which was not in the initial list followIDs. Is it normal that I track down ids from other users? Second question, how is it possible to track down not all user tweets but just the last 200 user tweets in twitterStream?
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
twitterStream.addListener(listener);
FilterQuery fq = new FilterQuery();
// fq.track(myQueries);
fq.follow(followIDs);
twitterStream.filter(fq);
ArrayList<FilterQuery> list = new ArrayList<FilterQuery>();
list.add(fq);
Using the follow parameter will result in the following Tweets being matched:
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply button (e.g. “#twitterapi I agree”).
source
I think you assumption is correct, this may account for the unknown ids.
Regarding obtaining the user's Tweets, you won't be able to use the streaming api for that as it's a real time view of Twitter. However, you may be able to use getUserTimeline(userId, paging) to retrieve the Tweets.
For a simple example of getUserTimeline in action, take a look at the GetUserTimeline example.

Handle the Post Request from Android?

I am writing an application with the user of Android Java " Eclipse " + Jquery Mobile + CodeIgniter Framework
I almost finished everything but still can not proceed on the push notification issue
one big problem taken about 2 days till now from me till I have headache from such conflict :
I made the POST Request from the android and it's already sending the POST Array.
here is the php code to handle the post request...
function notification() {
if($_POST['registrationId']) {
$this->session->set_userdata('registrationId', $_POST['registrationId']);
echo 'registerationID : success'.$this->session->userdata('registrationId').'====';
}
it really echo the session userdata indeed .. but when I try to use it in any other function or pages .. it's not working ? !!! it's empty or not existed ? !!
even when I try to make the query within the function in order to store it in Database .. the session is not available like $this->session->userdata('emailid')
update 'user' set deviceid ... where emailid = $this->session->userdata('emailid')
... not working and the session is not available !!!!!
PLEASE ANYONE CAN HELP ME ? !! :(
you can ues a class to storing the post data
class PostData {
public static $registrationId = "";
}
//set data
function notification() {
if(isset($_POST['registrationId']) && empty($_POST['registrationId']) {
PostData::$registrationId = $_POST['registrationId'];
}
}
// use data
$post_registrationId = empty(PostData::$registrationId) ? PostData::$registrationId : "";
well i couldn't solve the problem through sessions .. therefore i used fopen and i have registered the registration ID in a file.txt to use it later after in the session then delete the file. hope it can help someone someday .. thank you for sharing and participating

Search for tweets with pics/media ONLY using Twitter4j

I am trying to find a way to search for tweets with a specific hashtag AND tweets that only have pictures/media.
Searching for a hashtag is working:
Step #1
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#test");
query.setResultType(Query.RECENT);
query.setRpp(100);
QueryResult result = twitter.search(query);
.....
However, this returns all the most recent tweets up to 100 with the hashtag "test". Then I have to filter the ones with media
Step #2
Loop through the tweets and get the ones with media/pic
I want to skip step #2 and tell the query to retrieve only the ones with media. is that possible...I am particularly interested in the ones with pics.
Any help?
I know it's been a long time but this may help other people who want to learn the answer.
List<twitter4j.Status> tweets=result.getTweets();
for(twitter4j.Status tweet : tweets){
if(tweet.getMediaEntities().length!=0){//If there is media in a tweet
//Do anything you want with image
//tweet.getMediaEntities()[0].getMediaURL() is url of image in a tweet. For example:
publishProgress(tweet.getMediaEntities()[0].getMediaURL());
//Log.d(TAG, tweet.getMediaEntities()[0].getMediaURL()));
}
}
I know this is kinda late, but try including "pic.twitter.com" in your search. That won't have all the pictures, but you can add other urls as well.

Categories

Resources