I am using Jumblr(Tumblr API for Java) in my app to get all the dashboard posts from Tumblr. But I get only 20 posts in return. I want to increase the limit. I have looked into the Jumblr documentation
Kindly help me with this.
My code is below:
JumblrClient client = new JumblrClient(consumer_key, consumer_secret);
client.setToken(OAuthToken, OAuthSecretToken);
// Write the user's name
List<Post> posts = client.userDashboard();
System.out.print("\t"+posts.toString());
for (int i = 0; i<posts.size();i++) {
System.out.println("\t" + posts.get(i).getBlogName());
System.out.println("\t" + posts.get(i).getType());
System.out.println("\t" + posts.get(i).getPostUrl());
}
I found the solution to my problem in the Jumblr docs. I have to pass the options parameter to userDashboard().
Map<String, Integer> options = new HashMap<String, Integer>();
options.put("limit", 50);
List<Post> posts = client.userDashboard(options);
Related
I want to get tweets from certain user timelines using java library twitter4j, currently I have source code which can get ~ 3200 tweets from user time line but I can't get full tweet. I have searched in various sources on the internet but I can't find a solution to my problem. anyone can help me or can anyone provide an alternative to get a full tweet from the user timeline with java programming?
my source code :
public static void main(String[] args) throws SQLException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
int pageno = 1;
String user = "indtravel";
List statuses = new ArrayList();
while (true) {
try {
int size = statuses.size();
Paging page = new Paging(pageno++, 100);
statuses.addAll(twitter.getUserTimeline(user, page));
System.out.println("***********************************************");
System.out.println("Gathered " + twitter.getUserTimeline(user, page).size() + " tweets");
//get status dan user
for (Status status: twitter.getUserTimeline(user, page)) {
//System.out.println("*********Place Tweets :**************\npalce country :"+status.getPlace().getCountry()+"\nplace full name :"+status.getPlace().getFullName()+"\nplace name :"+status.getPlace().getName()+"\nplace id :"+status.getPlace().getId()+"\nplace tipe :"+status.getPlace().getPlaceType()+"\nplace addres :"+status.getPlace().getStreetAddress());
System.out.println("["+(no++)+".] "+"Status id : "+status.getId());
System.out.println("id user : "+status.getUser().getId());
System.out.println("Length status : "+status.getText().length());
System.out.println("#" + status.getUser().getScreenName() +" . "+status.getCreatedAt()+ " : "+status.getUser().getName()+"--------"+status.getText());
System.out.println("url :"+status.getUser().getURL());
System.out.println("Lang :"+status.getLang());
}
if (statuses.size() == size)
break;
}catch(TwitterException e) {
e.printStackTrace();
}
}
System.out.println("Total: "+statuses.size());
}
Update :
After the answer given by #AndyPiper
the my problem is every tweet that I get will be truncated or not complete. a tweets that I get will be truncated if the length of tweet more than 140 characters. I found the reference tweet_mode=extended, but I do not know how to use it. if you know something please tell me.
Your Configuration should be like this:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa")
.setTweetModeExtended(true);
It is explained well here
The Twitter API limits the timeline history to 3200 Tweets. To get more than that you would need to use the (commercial) premium or enterprise APIs to search for Tweets by a specific user.
if you are streaming tweets
fist: you have to add .setTweetModeExtended(true); into your configurationbuilder
second(here is the code)
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
System.out.println("-------------------------------");
if(status.isRetweet()){
System.out.println(status.getRetweetedStatus().getText());
}
else{
System.out.println(status.getText());
}`
its totally works for me.
take care yourself :)
If you are implementing twitter api using twitter4j.properties file and getting truncated timeline text value,simply add the below property in it at the end.
tweetModeExtended=TRUE
I am trying to search a large number of repositories with "searchRepository" method in https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core
However, there is a limitation to get more than 1000 results
https://developer.github.com/v3/search/#about-the-search-api
Since it will throw an exception "Only the first 1000 search results are available (422)" (based on the code example below)
A solution is presented in github search limit results
My question is how can I split up the search into segments by the date (as mentioned in the thread), or is there a another way to do this with the Java GitHub API.
int countRepos = 0;
Map<String, String> searchQuery = new HashMap<String, String>();
searchQuery.put("language", "java");
List<SearchRepository> searchRes = null;
GitHubClient client = new GitHubClient();
client.setCredentials("xxx", "xxxxx");
RepositoryService service = new RepositoryService(client);
for(int page = 1 ; page <12 ; page++){
try {
searchRes = service.searchRepositories(searchQuery,page);
} catch (IOException e) {
e.printStackTrace();
}
for(SearchRepository repo : searchRes){
System.out.println("Repository"+countRepos+": "+repo.getOwner()+"/"+repo.getName());
countRepos++;
}
}
System.out.println("Total number of repositories are="+countRepos);
Thanks in advance.
I want to implement express checkout link with 2CO payment gateway ; tested the following code:
public void testExpressCheckoutF()
{
Twocheckout.apiusername = "sonoratestw";
Twocheckout.apipassword = "sonorasonora";
Twocheckout.privatekey = "81DBF3R3-04B3-47DB-8068-ED3DAB20BC5A";
Twocheckout.mode = "sandbox";
HashMap<String, String> params = new HashMap<>();
params.put("sid", "901328163");
params.put("mode", "sandbox");
params.put("currency_code", "USD");
params.put("x_receipt_link_url", "http://www.test.com/summary_twocheckoutl_payment.xhtml");
params.put("comment", "some description");
params.put("li_0_product_id", "assdsdcas");
params.put("li_0_type", "product");
params.put("li_0_name", "test name");
params.put("li_0_quantity", String.valueOf(1));
params.put("li_0_price", String.valueOf(33));
params.put("li_0_description", "some description");
String expressCheckout = TwocheckoutCharge.url(params);
System.out.println("\n " + expressCheckout);
}
But when I run the code I always get ERROR CODE:PE104. I found this post as a possible solution http://help.2checkout.com/articles/Knowledge_Article/Error-Code-PE104/?l=en_US&fs=RelatedArticle
But still getting the same error. Can you propose some solution?
Please try removing the li_0_product_id param and trying again or changing the value to an integer and not a string. The article you linked to gives you general areas to start (no lineitems, invalid product_id, etc..) so it's just process of elimination at this point.
Recently I've been struggling with getting user information from post_id with java. I'm new in restfb, but after reasearching, below code should work. All available permissions are granted. Even in Graph API Explorer when writing post_id I cannot retrieve post's author details.
This is how I do it:
FacebookClient facebookClient = new DefaultFacebookClient(token);
String command = "orangepolska/feed";
Connection<Post> pagePosts = facebookClient.fetchConnection(command, Post.class);
ArrayList<String> postList = new ArrayList<String>();
String row;
for( List<Post> posts : pagePosts){
for (Post post : posts) {
if (post.getCreatedTime().after(startDate) && post.getCreatedTime().before(endDate)){
String message = post.getMessage();
CategorizedFacebookType postedBy = post.getFrom();
Post.Comments comments = post.getComments();
row = " owner: "+postedBy.getName()+" owner_id: "+postedBy.getId()+" post: "+message+" + " likes: "+post.getLikesCount() + "\n";
System.out.println(row);
postList.add(row);
}
}
}
return postList;
The problem occurs with various of functions like: getName(), getID(), getLikesCount() etc - these return null.
How can i fix it?
Thanks in advance.
You need to fetch the feed with the fields parameter so Facebook knows which fields you need to be filled. RestFB can only provide access to information that are given by Facebook ;)
Have a look here: http://restfb.com/#selecting-specific-fields
Norbert is correct but the link he posted did not work for me - you need to include "Parameter.with("fields", "from")" to get the user information.
Connection<Post> pagePosts = facebookClient.fetchConnection(command, Post.class, Parameter.with("fields", "from"));
I am trying to run Bing search API. I used odata4j and tried the code provided here:
How to use Bing search api in Java
ODataConsumer c = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search")
.setClientBehaviors(OClientBehaviors.basicAuth("accountKey", "{your account key here}"))
.build();
OQueryRequest<OEntity> oRequest = c.getEntities("Web")
.custom("Query", "stackoverflow bing api");
Enumerable<OEntity> entities = oRequest.execute();
After I registered in the bing service, I obtained the key and placed it inside the double quotation in the above code. I got the following error:
Exception in thread "main" java.lang.RuntimeException: Expected status OK, found Bad Request. Server response:
Parameter: Query is not of type String
at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:165)
at org.odata4j.consumer.AbstractODataClient.getEntities(AbstractODataClient.java:69)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.doRequest(ConsumerQueryEntitiesRequest.java:59)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.getEntries(ConsumerQueryEntitiesRequest.java:50)
at org.odata4j.consumer.ConsumerQueryEntitiesRequest.execute(ConsumerQueryEntitiesRequest.java:40)
at BingAPI.main(BingAPI.java:20)
Caused by: org.odata4j.exceptions.UnsupportedMediaTypeException: Unknown content type text/plain;charset=utf-8
at org.odata4j.format.FormatParserFactory.getParser(FormatParserFactory.java:78)
at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:161)
... 5 more
I could not figure out the problem.
All what you need is to set your query like that %27stackoverflow bing api%27
Here is my source code:
ODataConsumer consumer = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
.setClientBehaviors(
OClientBehaviors.basicAuth("accountKey",
"{My Account ID}"))
.build();
System.out.println(consumer.getServiceRootUri() + consumer.toString());
OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Web")
.custom("Query", "%27stackoverflow%27");
System.out.println("oRequest : " + oQueryRequest);
Enumerable<OEntity> entities = oQueryRequest.execute();
System.out.println(entities.elementAt(0));
You can further try different queries with different filters by keep adding name-value pairs by using .custom("Type of parameter","parameter") of the oQueryrequest object.Say you want to search for indian food but you want only small square images.
ODataConsumer consumer = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
.setClientBehaviors(
OClientBehaviors.basicAuth("accountKey",
"YOUR ACCOUNT KEY"))
.build();
System.out.println(consumer.getServiceRootUri() + consumer.toString());
OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Image")
.custom("Query", "%27indian food%27");
oQueryRequest.custom("Adult", "%27Moderate%27");
oQueryRequest.custom("ImageFilters", "%27Size:Small+Aspect:Square%27");
System.out.println("oRequest : " + oQueryRequest);
Enumerable<OEntity> entities = oQueryRequest.execute();
int count = 0;
Iterator<OEntity> iter = entities.iterator();
System.out.println(iter.next());