According to twitter documentation at https://dev.twitter.com/docs/api/1.1/get/friends/list
URL, I can change the value of "count"(The number of users to return per page) from default 20 to 200. But how can I specify the count option while calling getFriendsList api using Twitter4J java library.
According to the documentation if you're using getFriendsList you can only request up to 20 at a time. Might be a limitation of this java API
PagableResponseList<User> getFriendsList(long userId,
long cursor)
throws TwitterException
cursor - Causes the results to be broken into pages of no more than 20 records at a time.
The count parameter is not used in Twitter4J at the moment (as of 3.0.3).
This is what the code in question looks like:
public PagableResponseList<User> getFriendsList(long userId, long cursor) throws TwitterException {
return factory.createPagableUserList(get(conf.getRestBaseURL()
+ "friends/list.json?user_id=" + userId
+ "&cursor=" + cursor));
}
and
public PagableResponseList<User> getFriendsList(String screenName, long cursor) throws TwitterException {
return factory.createPagableUserList(get(conf.getRestBaseURL()
+ "friends/list.json?screen_name=" + screenName
+ "&cursor=" + cursor));
}
In order to retrieve more users with Twitter4J you'll have to use cursors and make multiple api calls, e.g.:
long cursor = -1;
PagableResponseList<User> friends;
do {
friends = twitter.getFriendsList(userId, cursor);
// collect users be adding to list etc...
} while ((cursor = followers.getNextCursor()) != 0);
N.B. A cursor value of zero signifies no further results.
Your code should look this way :
long cursor=-1;
int count=0;
while(cursor!=0)
{
PagableResponseList<User> friendlist= twitter.getFriendsList(user.getScreenName(),cursor);
int sizeoffreindlist= friendlist.size();
for(int i=0;i<sizeoffreindlist;i++)
{
//System.out.println(friendlist.get(i));
//Your Logic goes here
}
cursor=friendlist.getNextCursor();
System.out.println("====> New cursor value"+cursor);
}
Twitter responses cursor value 0 when no other pagable response i.e there are is no more friend list
The fix for this was checked into the code on 4/29/2014 (see this commit) and is available in the 4.0.2 Snapshot build today. So this will be part of v 4.0.2 and above.
Related
I have a simple celltable with:
a)A timer for retrieving the Whole list of values from the server (via rpc). when the data comes from the server:
public void onSuccess(final Object result) {
myList ((List<myObject>) result);
setRowData(myList);
}
b)A AsyncDataProvider to refresh the current displayed page, where:
protected void onRangeChanged(HasData<myObject> display) {
final Range range = display.getVisibleRange();
int start = range.getStart();
int end = start + range.getLength();
List<myObject> dataInRange = myList.subList(start, end);
// Push the data back into the list.
setRowData(start, dataInRange);
}
This works fine, refreshing the table when new data arrives from the server ..BUT....It jumps to the first page of my displayed table regardless he current page (Page size=20).
It is like it is ignoring the start and dataInRange values of the onRangeChanged method
the sentence:
setRowData(myList);
Is firing properly the onRangeChanged event of the DataProvider, but some how the 'start' values get 0
Any tip?
Many thanks
The problem is that when you call setRowData(myList); you also change the row range.
See the documentation:
Set the complete list of values to display on one page.
Equivalent to calling setRowCount(int) with the length of the list of values, setVisibleRange(Range) from 0 to the size of the list of values, and setRowData(int, List) with a start of 0 and the specified list of values.
Literally, below is the implementation:
public final void setRowData(List<? extends T> values) {
setRowCount(values.size());
setVisibleRange(0, values.size());
setRowData(0, values);
}
I've been asked to look at the creation of a report that will pull time entry data for a list of projects. Give the project name/id, retrieve a sum of all time spent on it, and a sum of the hours from the past week.
But I can't see where in the new API anything that will give me the time entries, at least, the retrieval process is not in the Basecamp documentation.
I've been looking at this page, which describes the API:
https://github.com/basecamp/bcx-api
Turns out that you can get it from their old API:
https://mystuff.basecamphq.com/projects/#project_id#/time_entries.xml
This will give you the time entries as XML, which is a pain. It also paginates the results. In the header that you get back are two fields, that tell you how many records are there total, and how many pages:
var pageCount = headers["X-Pages"];
var recCount = headers["X-Records"];
You can process the records that come back as follows:
function processRecords(response)
{
var respObj =
{
totalHours: 0,
thisWeekHours: 0
}
var doc = null;
if (response.getContentText)
{
doc = Xml.parse(response.getContentText(), true);
}
else if (response.getElements)
{
doc = response;
}
else
{
var name = typeof response;
if (response.constructor) name = response.constructor.name;
throw new Exception("Incompatible type: " + name);
}
var root = doc.getElement();
var records = root.getElements("time-entry");
if (records.length > 0)
{
for (i = 0;i < records.length; i++)
{
var hours = Number(records[i].hours.getText());
var recordDate = records[i].date.getText();
if (recordDate >= previousSunday && recordDate <= previousSaturday)
{
respObj.thisWeekHours = respObj.thisWeekHours + hours;
}
respObj.totalHours = respObj.totalHours + hours;
}
}
return respObj;
}
What we have seen so far is there is no easy way to get actual time spent on any project. You can do something simple like time from the day project is created till its closed/deleted.
The bet way we see doing this is looking at each todo-list and then to-dos under it. Find out the cumulative time spent on each to-do under each todo-list for that project and that will be the actual (nearest possible accurate time) time spent on the project.
You can use the API to get this todo level details and that will do the trick.
If someone has better option let us know as well :) We are doing the above as of today.
public void refresh()
{
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null, null, null);
int indexBody = smsInboxCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int indexAddress = smsInboxCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = smsInboxCursor.getString(indexBody) +
"\n" + smsInboxCursor.getString(indexAddress) + "\n";
arrayAdapter.add(str);
} while (smsInboxCursor.moveToNext());
}
in the above mentioned code, I want to display my mobile contact names with contact number in listview by using ArrayAdapter. now I obtain the solution in unsorted manner. But I want to display my contacts in sorted order. Can any one help me...
Easiest way to do that is to specify the sort order as part of your database query. Like so:
Cursor smsInboxCursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
You can use SQLite's ORDER BY syntax here.
Alternatively, you can use Collections.sort to sort your array directly.
I am working in Eclipse and am using 2 Java Files: Admin.java and SemanticSearch.java. Through the the Admin.java I am logging in and checking if the Username and Password are existing in my RDF file. The function of login in Admin.java calls SemanticSearch.java which runs a SPARQL Query. My Query is giving me the answer in Console of Eclipse and even onto another file. Now my job is to give back the answer to Admin.java either by returning the value or by counting rows and sending that value to Admin.java. With this if number of rows is 1 that means the username and password match and I can allow the user to login.
But I am not able to do so. I have tried using count(), Count() as CNT, even tried int res=results.next. But nothing seems to help.
I am pasting the code below:
Admin.java
SemanticSearch semsearch = new SemanticSearch(request.getSession());
semsearch.loadData(REALPATH + RDFDATASOURCEFILE1);
semsearch.searchForUser(response.getOutputStream(),null, userName, password);
In SemanticSearch.java
public void searchForUser(OutputStream out, String xslfile1, String userName, String password) {
String prolog = "PREFIX kb:<"+VUSER.getURI()+">";
System.out.println("Search for user in semantic search.java");
String queryString1 = prolog +"\n" +"SELECT * " +"WHERE {" +"?x kb:Uname ?username. ?x kb:Password ?password. ?x kb:Interest ?interest. " +"FILTER regex(?username, \"" +userName +"\")}";
System.out.println(queryString1);
Query query=QueryFactory.create(queryString1);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results1 = qexec.execSelect(); --> here the two rows are printed
int res=results1.getRowNumber();
System.out.println(results1); -->here answer is 0
ResultSetFormatter.out(results1);
ResultSetFormatter.out(out, results1);
System.out.println(res);
try {
if (xslfile1 != null)
{
out.write(ResultSetFormatter.asXMLString(results1, xslfile1).getBytes("UTF-8"));
System.out.println(results1);
System.out.println(xslfile1);
System.out.println("I am in if");
}
else
{
out.write(ResultSetFormatter.asXMLString(results1).getBytes(
"UTF-8"));
System.out.println("I am in else");
}
} catch (IOException e) {
e.printStackTrace();
}
}
Please Help, I am struggling to get this from a week, Regards, Archana.
In SPARQL 1.1, which may be supported in the triplestore you're using, the syntax is:
SELECT (COUNT(*) AS ?count)
WHERE {
...
}
You should get an integer returned in the ?count column, with the number of results.
Ok, I must be working too hard because I can't get my head around what it takes to use the Entity Framework correctly.
Here is what I am trying to do:
I have two tables: HeaderTable and DetailTable. The DetailTable will have 1 to Many records for each row in HeaderTable. In my EDM I set up a Relationship between these two tables to reflect this.
Since there is now a relationship setup between these tables, I thought that by quering all the records in HeaderTable, I would be able to access the DetailTable collection created by the EDM (I can see the property when quering, but it's null).
Here is my query (this is a Silverlight app, so I am using the DomainContext on the client):
// myContext is instatiated with class scope
EntityQuery<Project> query = _myContext.GetHeadersQuery();
_myContext.Load<Project>(query);
Since these calls are asynchronous, I check the values after the callback has completed. When checking the value of _myContext.HeaderTable I have all the rows expected. However, the DetailsTable property within _myContext.HeaderTable is empty.
foreach (var h in _myContext.HeaderTable) // Has records
{
foreach (var d in h.DetailTable) // No records
{
string test = d.Description;
}
I'm assuming my query to return all HeaderTable objects needs to be modified to somehow return all the HeaderDetail collectoins for each HeaderTable row. I just don't understand how this non-logical modeling stuff works yet.
What am I doing wrong? Any help is greatly appriciated. If you need more information, just let me know. I will be happy to provide anything you need.
Thanks,
-Scott
What you're probably missing is the Include(), which I think is out of scope of the code you provided.
Check out this cool video; it explained everything about EDM and Linq-to-Entities to me:
http://msdn.microsoft.com/en-us/data/ff628210.aspx
In case you can't view video now, check out this piece of code I have based on those videos (sorry it's not in Silverlight, but it's the same basic idea, I hope).
The retrieval:
public List<Story> GetAllStories()
{
return context.Stories.Include("User").Include("StoryComments").Where(s => s.HostID == CurrentHost.ID).ToList();
}
Loading the the data:
private void LoadAllStories()
{
lvwStories.DataSource = TEContext.GetAllStories();
lvwStories.DataBind();
}
Using the data:
protected void lvwStories_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Story story = e.Item.DataItem as Story;
// blah blah blah....
hlStory.Text = story.Title;
hlStory.NavigateUrl = "StoryView.aspx?id=" + story.ID;
lblStoryCommentCount.Text = "(" + story.StoryComments.Count.ToString() + " comment" + (story.StoryComments.Count > 1 ? "s" : "") + ")";
lblStoryBody.Text = story.Body;
lblStoryUser.Text = story.User.Username;
lblStoryDTS.Text = story.AddedDTS.ToShortTimeString();
}
}