Twitter4j Truncating Tweets - android

I am currently making a test application to retrieve tweets from a Twitter account and display them on the screen.
All my code is working fine, but a few Tweets are being truncated.
Anyone aware of what might be causing this and how to fix it?
Code for retrieving tweets:
Twitter twitter = new TwitterFactory().getInstance();
List<Status> statuses = null;
try
{
statuses = twitter.getUserTimeline("usu_unitec");
}
catch (TwitterException e)
{
e.printStackTrace();
}
ArrayList<String> news = new ArrayList<String>();
for (Status status : statuses)
{
news.add(status.getText());
}
return news;
Twitter account:
https://twitter.com/USU_Unitec
Example of Tweets being truncated:
Did you catch Aaradhna on Good Morning today? What did you think? We
were pretty blown away... Check out her... http ...
#USU_Unitec USU yous are awesome looking after us students , if I was
on campus I'd come and get it , but I'm on study leave ...
A reminder to check out our Summer School courses. You don't need to
be studying full time to get ahead! http://t.c ...

Why not use the Twitter JSON or XML API call directly? with this you can fetch all Tweets in full length :)
https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

Related

Can't get the list of accounts using Google Contacts API & OAuth 2.0

I'm trying to retrieve a Google user's contacts list.
This getContacts() is called in the doInBackground() of an AsyncTask.
I have -at this point- already received a token.
I based my self on this codeLab sample : https://codelabs.developers.google.com/codelabs/appauth-android-codelab/#0
I'm modifying the point n°10 of this tutorial so trying to fetch user's contact list instead of the user's personal info ( < which is working)
private List<ContactEntry> getContacts() {
ContactsService contactsService = new ContactsService("MY_PRODUCT_NAME");
contactsService.setHeader("Authorization", "Bearer " + token);
try {
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl);
ContactFeed resultFeed = contactsService.query(myQuery, ContactFeed.class);
List<ContactEntry> contactEntries = resultFeed.getEntries();
return contactEntries;
} catch (Exception e) {
}
return null;
}
My problem is that I always get an Exception with this message :
java.lang.NullPointerException: No authentication header information
Any help?
thanks in advance
You may refer with this related thead. Try modifying the client library's user
agent:
A workaround is to change the user agent of your client after you create it:
ContactsService service = new ContactsService(applicationName);
service.getRequestFactory().setHeader("User-Agent", applicationName);
Also based from this post, service.setOAuth2Credentials() doesn't refresh token internally like the other services in Google Sites, Google Drive and etc. If you build Google Credential, just add this line after building the Google Credential: googleCredential.refreshToken();.

How to tell the if the City is incorrect in OpenWeatherMap api and in android

I am creating an app which will tell the weather condition of a city using the OpenWeatherMap.org api. In this app I let user to write a city name and the data will be fetched from the web. But what if the user entered wrong city.
For example if a user entered Lomdon instead of London.
What should I do in that case. The Api I am using is
"http://api.openweathermap.org/data/2.5/weather?q="+city name
Thanks in advance for the help, I am new to android development.
If the city is incorrect your API returns an error message. You can check it like this:
"http://api.openweathermap.org/data/2.5/weather?q=Lomdon"
try {
String msg = jsonObject.getString("message");
if (msg.equalsIgnoreCase("Error: Not found city")) {
Log.e("TAG", "City not found");
} else {
// Use the data
}
} catch (JSONException e) {
e.printStackTrace();
}
The reason I didn't use cod which looks like the return code, is that if the city is found cod is an int and if it's not found it's a string. Kind of misleading to design the JSON like that.

Twitter4j not returning any results on Android

Since Twitter moved to API v1.1, I've tried switching to Twitter4j to perform my queries. I've set up my dev account on twitter and I'm pretty sure I've set up OAuth ok:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey("XXX")
.setOAuthConsumerSecret("XXX")
.setOAuthAccessToken("XXX")
.setOAuthAccessTokenSecret("XXX");
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
System.setProperty("twitter4j.debug", "true");
try
{
String url = "q=%40twitterapi%20-via";
Query query = new Query(url);
QueryResult result;
do
{
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets)
{
results.add(getInfoFromTweet(tweet));
}
} while ((query = result.nextQuery()) != null);
} catch (TwitterException te)
{
Log.e(TAG, "Problem gettibng results from twitter: " + url, te);
}
The main problem is that I never get any tweets returned in the results, though results itself seems rasonably well formed as far as I can see. The query string I'm using certainly seems to give plenty of results when I try it directly in a web browser: https://twitter.com/search/realtime?q=%40twitterapi%20-via
The other thing is that I can't work out how to get the debugging output from Twitter4j in Android. I've tried everything that I can find to get the debug output, but it's either not coming out or I'm not looking in the right place!

Send App request to all friends in Facebook using 'Requests Dialog' in Android

I want to know how to send app request to all my facebook friends from android app. I tried in graph API. But, couldn't get it done.
https://graph.facebook.com/apprequests?ids=friend1,friend2&message='Hi'&method=post&access_token=ACCESS_TOKEN
I know this is a Duplicate question. But, couldn't find an answer yet.
I'm getting this error on the above API.
"All users in param ids must have accepted TOS."
I hope there will be a way to send app request to all friends from mobile on a click. Please share it.
The error message you receive ("All users in param ids must have accepted TOS") is because you are trying to send an app generated request to a user who is not connected to your app.
See the developer docs here.
Requests sent with the request dialog and app generated requests are different and you can't use app generated requests to invite users to your app.
Sending Facebook app requests are not available via the graph api. You can use the app requests java-script dialog to send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.
Sample function:
<script>
FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });
function sendRequest(to) {
FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
return false;
}
</script>
Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"
Also you can call this function in javascript: It will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: "You should learn more about this awesome site."
});
}
See Facebook Friend Request - Error - 'All users in param ids must have accepted TOS'
Have you seen demo of "Hackbook" in the developer.facebook.com ?
You can refer HACKBOOK APP REQUEST FROM HERE.
You can achieve to post the app request to only one friend by below code.
Code:
Bundle params = new Bundle();
JSONObject attachment = new JSONObject();
JSONObject properties = new JSONObject();
JSONObject prop1 = new JSONObject();
JSONObject prop2 = new JSONObject();
JSONObject media = new JSONObject();
JSONStringer actions = null;
try {
attachment.put("name", "YOUR_APP");
attachment.put("href", "http://www.google.com/");
attachment.put("description", "ANY_TEXT");
media.put("type", "image");
media.put("src", "IMAGE_LINK");
media.put("href", "http://www.google.com/");
attachment.put("media", new JSONArray().put(media));
prop1.put("text", "www.google.com");
prop1.put("href", "http://www.google.com");
properties.put("Visit our website to download the app", prop1);
/* prop2.put("href", "http://www.google.com");
properties.put("iTunes Link ", prop2);*/
attachment.put("properties", properties);
Log.d("FACEBOOK", attachment.toString());
actions = new JSONStringer().object()
.key("name").value("APP_NAME")
.key("link").value("http://www.google.com/").endObject();
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("ACTIONS STRING: "+actions.toString());
System.out.println("ATTACHMENT STRING: "+attachment.toString());
params.putString("actions", actions.toString());
params.putString("attachment", attachment.toString()); // Original
params.putString("to", "YOUR_FRIEND_FACEBOOK_ID");
Utility.mFacebook.dialog(getParent(), "stream.publish", params,new PostDialogListener());
public class PostDialogListener extends BaseDialogListener {
#Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_posted), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_not_posted), Toast.LENGTH_SHORT).show();
}
}
}
Above code works perfect if you want to post the Apprequest only on One friend's wall. If you want to post on all then you have to make asynckTask which runs for all the friends post and post App request on all walls.
Update
Here is the link in PHP that have done same work to send request to all Facebook friends.
And [here it is clearly explained3 that it is blocked by Facebook to send a Friend Request to more then 15-20 friends.
Now, you have to only one option to do it is, use above code in AsyncTask to send Friend Request to all Friends One-by-One.

How to Integrate Twitter Oauth as like Facebook?

I am new to integrating Twitter. I have implemented Twitter in my application with this code:
// Create file
File picture = new File(APP_FILE_PATH + "/myAwesomeDrawing.png");
// Create TwitPic object and allocate TwitPicResponse object
TwitPic tpRequest = new TwitPic("username", "password");
TwitPicResponse tpResponse = null;
// Make request and handle exceptions
try {
tpResponse = tpRequest.uploadAndPost(picture, "Image Uploaded from My AndroidDrawing App...");
}
catch (IOException e) {
e.printStackTrace();
}
catch (TwitPicException e) {
e.printStackTrace();
}
// If we got a response back, print out response variables
if(tpResponse != null)
tpResponse.dumpVars();
All works fine here. But here I have to add the username and password programmatically. Is there any other way to use the Twitter integration as like Facebook OAuth to integration?
I need to know how Twitter OAuth is checked, and if the User is not login then it will ask for the username and password in its in built window.
If caguilar187's code link's are not enough, then here are few more links for code help:
http://blog.doityourselfandroid.com/2011/08/08/improved-twitter-oauth-android/
http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/
http://marakana.com/forums/android/examples/312.html
Best suggested: http://android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application
One more suggest: http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html
Post on Twitter: http://www.londatiga.net/it/how-to-post-twitter-status-from-android/
GitHub Link: https://github.com/brione/Brion-Learns-OAuth
Hope below link help you:-
Below link show you how to generate key with Twitter and other social media
http://code.google.com/p/socialauth-android/wiki/Twitter
Now below link is source code where u find out source code
http://code.google.com/p/socialauth-android/downloads/list
here are a few they all use signpost to do it.
Signpost:
http://code.google.com/p/oauth-signpost/
Blogs
http://dev.bostone.us/2009/07/16/android-oauth-twitter-updates/#awp::2009/07/16/android-oauth-twitter-updates/
http://blog.copyninja.info/2010/09/android-oauth-authentication-with.html
http://code.google.com/p/oauth-signpost/wiki/TwitterAndSignpost

Categories

Resources