Show last and early tweet with Twitter API android - android

hello i just learn API Twitter in android. At the start of my application, is shows 20 tweets with this URL
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20
I want to display the last 20 before 20 tweets that have been shown (with load endless) and all new tweet after tweet earlier 20 (with pull to refresh). but i don't know how the URL or method to get 20 last or newest tweet . how it's work ? sorry for my english.

You need this page: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline found on this well documented page (https://dev.twitter.com/docs/api/1.1)
The URI you likely want though is:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20&max_id=[lowest-id-from-last-batch]

If you're on Android I recommend using the Twitter4J library for easy Twitter API calls and response handling.
With use of Paging you can get the next 20 tweets (using Paging.page) or new tweets (using id's or time/since).
Code example for getting a Users timeline using Twitter4J in Android:
// Use as field
Twitter twitter;
// Get timeline
try {
if(twitter==null) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(Constants.DEBUG)
.setOAuthConsumerKey("YOUR CONSUMER KEY")
.setOAuthConsumerSecret("YOUR CONSUMER SECRET")
.setApplicationOnlyAuthEnabled(true)
.setHttpConnectionTimeout(5000)
.setHttpReadTimeout(5000)
.setHttpStreamingReadTimeout(5000);
twitter = new TwitterFactory(cb.build()).getInstance();
twitter.getOAuth2Token();
}
return twitter.getUserTimeline("TwitterName", twitterPaging);
} catch (Exception e) {
e.printStackTrace();
}

Related

Outlook - Read another user's calendar

I'm developing an Android App based on Outlook-SDK-Android. The App talks with Outlook Calendar REST API to retrieve, book and delete events (see code examples here and here). Now I need to read someone else's calendar and I've been provided an Office365 account with delegate access (author permission level) towards other users.
I've registered my app using the provided account on the new portal. In my App I use the scope "https://outlook.office.com/Calendars.ReadWrite".
(The scope is used in com.microsoft.aad.adal.AuthenticationContext.acquireToken() to initialize an Office REST Client for Android OutlookClient, a shared client stack provided by orc-for-android)
When I try to read another user's calendar on which I have delegate access I just receive back a 403 response:
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again."
}
}
Any help?
Is it a limitation of the API? If so why is the following method invocation chain provided then?
outlookClient.getUsers()
.getById("meetingRoom#company.com")
.getCalendarView()
UPDATE:
It seems like there are works in progress that will allow this scenario, as reported here: Office 365 REST API - Access meeting rooms calendars
So if progress in that direction has been made can I achieve my goal without using an "admin service app"? (see Office 365 API or Azure AD Graph API - Get Someone Elses Calendar)
Can I use basic authentication as suggested here?
Calendar delegation is a feature of Exchange, the Graph API and Outlook API do not allow the user to access the delegated calendar.
Currently, the alternative workaround could be use the EWS. And here is an sample for your reference:
static void DelegateAccessSearchWithFilter(ExchangeService service, SearchFilter filter)
{
// Limit the result set to 10 items.
ItemView view = new ItemView(10);
view.PropertySet = new PropertySet(ItemSchema.Subject,
ItemSchema.DateTimeReceived,
EmailMessageSchema.IsRead);
// Item searches do not support deep traversal.
view.Traversal = ItemTraversal.Shallow;
// Define the sort order.
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
try
{
// Call FindItems to find matching calendar items.
// The FindItems parameters must denote the mailbox owner,
// mailbox, and Calendar folder.
// This method call results in a FindItem call to EWS.
FindItemsResults<Item> results = service.FindItems(
new FolderId(WellKnownFolderName.Calendar,
"fx#msdnofficedev.onmicrosoft.com"),
filter,
view);
foreach (Item item in results.Items)
{
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Id: {0}", item.Id.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Exception while enumerating results: { 0}", ex.Message);
}
}
private static void GetDeligateCalendar(string mailAddress, string password)
{
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials(mailAddress, password);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(mailAddress, RedirectionUrlValidationCallback);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(AppointmentSchema.Subject, "Discuss the Calendar REST API"));
DelegateAccessSearchWithFilter(service, sf);
}
And if you want the Outlook and Graph API to support this feature, you can try to contact the Office developer team from link below:
https://officespdev.uservoice.com/
FindMeetingTimes is currently in preview! To view the details, use this link and then change it to view the Beta version of the article (top right in the main column): https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#Findmeetingtimespreview
Details below from the article, but please use the link to get the latest:
Find meeting times (preview)
Find meeting time suggestions based on organizer and attendee availability, and time or location constraints.
This operation is currently in preview and available in only the beta version.
All the supported scenarios use the FindMeetingTimes action. FindMeetingTimes accepts constraints specified as parameters in the request body, and checks the free/busy status in the primary calendars of the organizer and attendees. The response includes meeting time suggestions, each of which is defined as a MeetingTimeCandidate, with attendees having on the average a confidence level of 50% chance or higher to attend.

Can twitter4j fetch more than 1 picture from a tweet?

I am new to twitter4j and i try to fetch a couple of tweets, it all work fine except for the tweets with multiple pictures.
For example, if i tweet 4 pictures at the same time (yes now twitter allow us to tweet up to 4 pictures from their mobile application), i only manage to fetch the 1st picture.here is my code:
for (twitter4j.Status status : result.getTweets()) {
if (status.getMediaEntities() != null)
{
for (MediaEntity media : status.getMediaEntities())
{
//for some reason getMediaEntities() return an array with the first pic uploaded only
}
}
}
Tahnks for your help.
Just use status.getExtendedMediaEntities()

Getting Friends List Empty Facebook SDK 3.8 in Android

I am trying to fetch friends' list in Facebook SDK 3.8 but it returning Empty User List.
I have also set the permissions of user_friends. Please see the following code.
<code>
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("user_friends"));
Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
Log.i("activitytag", "UserListSize: " + users.size());
}
});
request.executeAsync();
</code>
I am getting the UserListSize to 0. What am I missing?
If you created your app after April 30, 2014, then you're using version 2.0 of the graph API, in which case the newMyFriendsRequest will only return friends who are also using your app. You should also update your SDK to the latest (3.14.1).
In facebook api v2.0 has no way to get all friends list.
but if you want to get all friend list ONLY IN GAME then you can call
Either
Invitable Friends List:
you may use the https://developers.facebook.com/docs/graph-api/reference/v2.0/user/invitable_friends API.
OR
Taggable Friends List:
the https://developers.facebook.com/docs/graph-api/reference/v2.0/user/taggable_friends
for more detail please read facebook change log:
Facebook Change log

How to post a tweet from an Android app to one specific account?

I have to add an option to my game for posting highscores to twitter. The idea is that the app has it's own twitter account and the user can upload the score to this specific account with a click on a button or a menu item (haven't decided how the UI looks like yet).
I have found many tutorials like this:
http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/
,which show how to post to twitter from apps but in all of these solutions the user needs to login with his/her own account.
Any suggestions are welcome. Thank you.
I have found a solution for this problem. Thought I share it here in case anyone has the same problem.
First you need to create the account for your app on twitter
Go to this page and log in with the created account
Move your mouse over your account name in the upper right corner and
click "My applications"
Click on "Create a new application" on the right
Fill in the form and create the application
Go to Settings and under Application type set the Access type to
"Read and Write" and save the settings
Return to the "Details" page and scroll down to the bottom and click
the "Create access token" button
Use these generated tokens and the other ones ("Consumer key" and
"Consumer secret") which are shown above these previously generated
tokens on the same page to post tweets from your app
Here's the code I used in my app:
You need to include the twitter4j-core-android-2.2.5.jar package for this. You can download it from here: http://twitter4j.org/archive/twitter4j-android-2.2.5.zip
tweet=(Button)findViewById(R.id.tweetbtn);
message=(EditText)findViewById(R.id.messagetxt);
tweet.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String token ="<Your access token>";
String secret = "<Your access token secret>";
AccessToken a = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("<Your consumer key>", "<Your consumer secret>");
twitter.setOAuthAccessToken(a);
try {
twitter.updateStatus(message.getText().toString());
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
the new link for download
http://twitter4j.org/archive/twitter4j-android-2.2.5.zip
old link does not work

How to get facebook page's stream with facebook-android-sdk

I followed steps here: https://developers.facebook.com/docs/guides/mobile/#android
but I really don't get how use Graph API to get a Page's stream (only news) for Android.
Someone can make me an example? I cannot also find a real good example online searching with Google...
There's a good Graph API explorer here, getting a page info is simple as using GET request with the page id.
https://graph.facebook.com/<PAGE_ID>
So you can use the Simple Sample found here
//Page id for Bristol (my hometown) but could use something like 'cocacola'
String PAGE_ID="108700782494847"
mBristolPageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//get the request aysn and process JSON response with the Listener
mAsyncRunner.request(PAGE_ID, new MyPageRequestListener());
}
});
To get the feed/news from a page put /feed on the end [However you may require a auth_token to get news stream]
https://graph.facebook.com/<PAGE_ID>/feed

Categories

Resources