i am developing and application in which i want to get some feeds from twitter like picture, name, tweets, time and number of reply on each tweet. i did all but could not get number of reply for each tweet.... help me out thanks in advance..
i am posting my code also.
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("BeingSalmanKhan",paging);
for (Status status3 : statuses)
{
TwitterFeeds tFeeds = new TwitterFeeds();
System.out.println(status3.getText());
tFeeds.strTweet = status3.getText();
tFeeds.strDate = status3.getCreatedAt().toString();
System.out.println("---------------------------------- " + status3.getSource());
al_tweets.add(tFeeds);
}
str_tw_name = unauthenticatedTwitter.showUser("BeingSalmanKhan").getName();
str_tw_imgurl = unauthenticatedTwitter.showUser("BeingSalmanKhan").getProfileImageURL().toString();
bitmap_twpic = NewsActivity.DownloadImage(str_tw_imgurl);
Try this snippet of code... it worked for me.. hope for you too
try {
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
//URLEntity[] uent=
//First param of Paging() is the page number, second is the number per page (this is capped around 200 I think.
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("ashabhosle",paging);
System.out.println("status no 2 ="+statuses.get(2).toString());
long retweetcnt=statuses.get(2).getRetweetCount();
System.out.println("retweet count on 2nd tweet "+retweetcnt);
for (Status status3 : statuses)
{
System.out.println(status3.getText());
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to get timeline: " + e.getMessage());
}
try getRelatedResults(),gives a list of replies + mentions,it is the closest to getting replies.
Related
i have a openfire server running on my localhost and i am successfully able to send and receive messages to registered users. however i am not been able to get all users from server. i am logged in with user that doesn't have a administration access. so do i need to give any permission on server side?
The code i am using for getting all users is..
if ( xmpp.getConnection()== null || !xmpp.getConnection().isConnected())
return;
try {
UserSearchManager usm = new UserSearchManager(xmpp.getConnection());
Form searchForm = usm.getSearchForm("search." + xmpp.getConnection().getServiceName());
Form answerForm = searchForm.createAnswerForm();
UserSearch userSearch = new UserSearch();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", userName);
ReportedData data = userSearch.sendSearchForm(xmpp.getConnection(), answerForm, "search." + xmpp.getConnection().getServiceName());
for (ReportedData.Row row : data.getRows())
{
arrayList.add(row.getValues("Username").toString());
}
} catch (Exception e) {
e.printStackTrace();
}
i tried some solutions that shows to use Roster class, however that is also not helping me. Can anyone show what i am doing wrong or if i need to give any permission as i am not logged in as admin?
The error i am getting is..
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: remote-server-not-found
Thanks :)
This is how I am getting all users from openfire
You actually have to pass wildcard(*) for the username
Here's the working code
Utils.getConnection() - my xmpp connection
public static void getAllXmppUsers()
{
try {
UserSearchManager manager = new UserSearchManager(Utils.getConnection());
String searchFormString = "search." + Utils.getConnection().getServiceName();
Log.d("***", "SearchForm: " + searchFormString);
Form searchForm = null;
searchForm = manager.getSearchForm(searchFormString);
Form answerForm = searchForm.createAnswerForm();
UserSearch userSearch = new UserSearch();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", "*");
ReportedData results = userSearch.sendSearchForm(Utils.getConnection(), answerForm, searchFormString);
if (results != null) {
List<ReportedData.Row> rows = results.getRows();
for (ReportedData.Row row : rows) {
Log.d("***", "row: " + row.getValues("Username").toString());
}
} else {
Log.d("***", "No result found");
}
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
Try this code. I tweak this code from this answer
UserSearchManager usm= new UserSearchManager(xmpp.getConnection());
Form searchForm = usm.getSearchForm("search." +xmpp.getConnection().getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", userName);
ReportedData data = usm
.getSearchResults(answerForm, "search." + xmpp.getConnection().getServiceName());
if (data.getRows() != null) {
for (ReportedData.Row row: data.getRows()) {
for (String jid:row.getValues("jid")) {
System.out.println(jid);
}
}
}
Smack is used to create a client. A client is used by one user. A user typically does not have access to all users of the server. Users do have contact lists, or rosters though, where you an add other users.
I'm trying to retrieve tweets that mention an specific user either using fabric for android or twitter4j, but I'm not getting anything.
-With Fabric for Android I'm doing it with "twitterApiClient.getSearchService().tweets" (logged in as a guest previously)
-With twitter4j, this is my code:
public List<Long> twList (String user){
List<Long> listTw = new ArrayList<>();
lastID = Long.MAX_VALUE;
int tamano = 0;
ArrayList<Status> tweets = new ArrayList<Status>();
String mention = "#"+user.trim();
query = new Query(user);
while (tweets.size() < numberOfTweets) {
tamano = tweets.size();
if (numberOfTweets - tweets.size() > 100) {
query.setCount(100);
} else {
query.setCount(numberOfTweets - tweets.size());
}
try {
QueryResult result = twitter.search(query);
tweets.addAll(result.getTweets());
Log.d("App", "Gathered " + tweets.size() + " tweets");
for (Status t : tweets) {
if (t.getId() < lastID) {
lastID = t.getId();
}
}
} catch (TwitterException te) {
Log.d("App", "Couldn't connect: " + te);
}
query.setMaxId(lastID - 1);
if (tamano == tweets.size()) break;
}
for (Status s: tweets){
if (s.getText().matches(mention)){
listTw.add(s.getId());
Log.d("App", s.getText());
}
}
tweets.clear();
return listTw;
}
When I look for the username on Twitter website, I get those tweets where it's mentioned.
Any idea?
When was the last time a Tweet including the username you're searching for, posted? The Search API (which is used by both Fabric and Twitter4j) only covers around 7 days of data. The website has the complete archive, but that is not available in the public Twitter API.
I followed this tutorial http://kodefun.junian.net/2011/10/easy-facebook-android-sdk-simple.html and managed to successfully connect to facebook.
But how do I get user photos? Here's the code so far:
...
public void loginSuccess(Facebook facebook) {
GraphApi graphApi = new GraphApi(facebook);
User user = new User();
try{
user = graphApi.getMyAccountInfo();
//update your status if logged in
graphApi.setStatus("Hello, world!");
} catch(EasyFacebookError e){
Log.d("TAG: ", e.toString());
}
fbLoginManager.displayToast("Hey, " + user.getFirst_name() + "! Login success!");
List<Photo> listPh = graphApi.getAllPhotosMy();
Photo ph = listPh.get(0);
/// ... how do I get a user photo to drawable or something?
}
...
Any ideas? :) Thanks!
Just from messing around in there reference, I would say you would get the persons's ID and the feed that into a from, and then feed that from into the photo again.
I'm no expert on this, but there documentation is your friend.
http://www.easyfacebookandroidsdk.com/doc/index.html
I have successfully completed this: http://www.sitepoint.com/loading-twitter-data-into-android-with-lists/ tutorial and have gotten my app to display tweets based on a search criteria.
What I want my app to do is display the timeline of a specific user.
From that tutorial I have replaced my get line with this:
HttpGet("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=android");
I am getting no results in my listview.. I shouldn't need to authenticate user name and password because all I want to do is display the timeline, not manipulate it.
If you are using Twitter4j this is pretty easy :
public final class GetTimelines {
/**
* Usage: java twitter4j.examples.GetTimelines ID Password
* #param args String[]
*/
public static void main(String[] args) {
Twitter unauthenticatedTwitter = new TwitterFactory()
.getInstance();
System.out.println("Showing public timeline.");
try {
List<Status> statuses = unauthenticatedTwitter
.getPublicTimeline();
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
if (args.length < 2) {
System.out
.println("You need to specify TwitterID/Password combination to show UserTimelines.");
System.out
.println("Usage: java twitter4j.examples.GetTimelines ID Password");
System.exit(0);
}
// Other methods require authentication
Twitter twitter = new TwitterFactory().getInstance(args[0],
args[1]);
statuses = twitter.getFriendsTimeline();
System.out.println("------------------------------");
System.out.println("Showing " + args[0]
+ "'s friends timeline.");
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
statuses = twitter.getUserTimeline();
System.out.println("------------------------------");
System.out.println("Showing " + args[0] + "'s timeline.");
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
Status status = twitter.showStatus(81642112l);
System.out.println("------------------------------");
System.out.println("Showing " + status.getUser().getName()
+ "'s status updated at " + status.getCreatedAt());
System.out.println(status.getText());
System.exit(0);
} catch (TwitterException te) {
System.out.println("Failed to get timeline: "
+ te.getMessage());
System.exit(-1);
}
}
}
Sample taken from here
you can get the answer of ur question at https://github.com/robhinds/AndroidTwitterDemo
or
http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html
use twitter4j jar for same
hope will help u ...
If you just want to fetch user timeline than the best way is -
twitter4j jar file - http://twitter4j.org/archive/twitter4j-3.0.3.zip
To register your app go to dev.twitter.com
We can fetch the use timeline by using twitter oauth and for this process we don't need to provide any user credentials
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
builder.setOAuthAccessToken(TWITTER_ACCESS_KEY);
builder.setOAuthAccessTokenSecret(TWITTER_ACCESS_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
Twitter twitter = factory.getInstance();
Paging page = new Paging();
page.setCount(100);
List<Status> statuses = new ArrayList<Status>();
statuses = twitter.getUserTimeline("write username here", page);
for (Status status : statuses) {
System.out.println("title is : " + status.getText());
}
Twitter has introduced Fabric SDK for needs like yours. Here is a site: Twitter Fabric. When you install SDK you will have new icon in your Android studio for Fabric Sdk. You have to install Twitter kit and use embed tweets. For user timeline you have to use UserTimeline. Also , you have some project in github that can help you understand how Twitter kit works:
Github repo
I'm making an application that is posting some information to your facebook wall using facebook sdk for android. This works, but I can't seem to get new lines on the posts. I have tried \n but it doesent work. Any suggestions?
Here is my code:
Bundle parameters = new Bundle();
String temp = "";
for (int i = 0; i < mArrayAdapter.getCount(); i++){
temp = temp + mArrayAdapter.getItem(i) + "\n"; // Not working
}
parameters.putString("message", temp);
mFacebook.dialog(this, "stream.publish", parameters, new DialogListener());
Thanks,
James Ford
Hi James i have tried that before, even with html code but i think thats not possible.
The reason, Facebook must have a control to avoid blank spaces or line break on his posts.
New lines are not allowed in stream posts (the fact that you may have seen them in the past are bugs on facebook).
make use of JSON to post on facebook..
how? look here
STEPS :-
Step 1 :- At this link u will came to know how to use JSON for setting text to TEXTVIEW.
Step 2 :- May be this is not u r looking for :) assign the text of textview to some string
using GetText().ToString
Step 3 :- use this string to post to the facebook.
Step 4 :- I did the same after spending lot of time in googling and finally got the result
by using this trick. u can see my post that i posted during test here
Step 5 :- set the visibilty of this text box to gone using
tv.setVisibility(View.GONE)
And u r done with your posting to facebook..
let the facebook and textview handle how they manage spaces and new line character :D
Some Coding work for newbies like me...
I am posting it on click of button
1)
tv= (TextView)findViewById(R.id.tv);
click=(Button)findViewById(R.id.btn1);
click.setOnClickListener(mthdpost);
2) add on click event to this button
private View.OnClickListener mthdpost=new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
String json = "{"
+ " \"name\": \"myName\", "
+ " \"message\": [\"myMessage1\",\"myMessage2\"],"
+ " \"place\": \"myPlace\", "
+ " \"date\": \"thisDate\" "
+ "}";
/* Create a JSON object and parse the required values */
JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
String name = object.getString("name");
String place = object.getString("place");
String date = object.getString("date");
JSONArray message = object.getJSONArray("message");
String MessageToPost= null;
tv.setText("Name: "+ name +"\n\n");
tv.append("Place: "+ place +"\n\n");
tv.append("Date: "+ date +"\n\n");
/*JSONObject attachment = new JSONObject();
attachment.put("Name: ","\n\n");
attachment.put("Place: ","\n\n");
attachment.put("Date: ","\n\n");*/
for(int i=0;i<message.length();i++)
{
tv.append("Message: "+ message.getString(i) +"\n\n");
//attachment.put("Message: ","\n\n");
}
MessageToPost=tv.getText().toString();
postToWall(MessageToPost);// called the method having logic to post on wall and sending the textview text to to post as message
} catch (JSONException e)
{e.printStackTrace();
}
catch(Exception ex)
{ex.printStackTrace();}
}
};
3) method for posting the message
public void postToWall(String msg){
Log.d("Tests", "Testing graph API wall post");
try {
String response = facebook.request("me");
Bundle parameters = new Bundle();
//parameters.putString("message", msg.toString());
parameters.putString("message", msg);
parameters.putString("description", "test test test");
response = facebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
}
HOPE IT WILL HELP :)
This worked for me:
StringBuilder messageData = new StringBuilder(title).append('\n')
.append('\n').append(message).append('\n').append('\n')
.append(description);
// Message
postParams.putString("message", messageData.toString());
This works:
Use this: <center></center>
Instead of a br or a newline, etc. You can only do one in a row (ie. you can't increase the spacing).