how do i share a post on facebook using restfb - java

this is my java code using resfb lib to post something on my facebook groups feed:
FacebookClient fb=new DefaultFacebookClient(token);
FacebookType message=fb.publish(pid+"/feed",FacebookType.class,Parameter.with("message", description));
now what do i do to share posted article?
thanks a lot for your help!

Graph API doesn't provide an explicit share operation, but you can create a post which is a link to another post, which should be displayed as a share. Something like this:
fb.publish("me/feed", FacebookType.class, Parameter.with("link", "https://www.facebook.com/10152237769155733"));

Related

RestFB getting Conversations

Iam using restfb to get in touch with Facebook from our application.
I have link to the conversation
https://www.facebook.com/prasannapatireddy/posts/234992897106899?comment_id=263969987542523
Now what I need is using above link I have to find out the Attachments if any in this conversation.
How can we do this in Java.
I tried below but didn't work
'
Connection myFeed = facebookClient
.fetchConnection("https://www.facebook.com/prasannapatireddy/posts/234992897106899?comment_id=263969987542523",Comment.class);
Please Help.
Thanks & Regards,
Prasanna
You have to provide the information in your call which fields you need. And you cannot use the perma link of a comment you see on Facebook, this is all about the Graph API.
Connection<Comment> commentConnection = facebookClient.fetchConnettion("<comment_id>",
Comment.class, Parameter.with("fields", "attachment"));
The comment id should be fetched via graph api or with some luck you can try to build it by hand.

Google books api always returns nothing

I am trying to use Google books API but for any request I receive totalItems = 0.
I've tried to send the request in chrome, for example:
https://www.googleapis.com/books/v1/volumes?q=flowers+inauthor:keyes&key=MY_KEY
Also I've tried the approach, described here:
https://github.com/google/google-api-java-client-samples/blob/master/books-cmdline-sample/src/main/java/com/google/api/services/samples/books/cmdline/BooksSample.java
And for any query with any parameters I always receive nothing:
{
"kind": "books#volumes",
"totalItems": 0
}
I generated key using developer console: https://console.developers.google.com and selected option Api Key.
I will appreciate any help with this issue.
Thanks in advance!
As I've understood, the problem is in my country(Belarus). Looks like Google Books APi doesn't work in Belarus. Problem can be fixed by using VPN.

I cannot get published blog post with wp.getRecentPosts(int)

I am using XML-RPC and Jwordpress to view my site posts.
When I Use the following code:
Wordpress wp = new Wordpress(Username, Password, XMLRPCURL);
List<Page> recentPost = wp.getRecentPosts(10);
It returns only Drafts. How can I retrieve my Published Posts with JWordpress?
Best Thing to do is to Use Json API.
easily Install JSON on Your WordPress Site or Blog and with JSON Library for Java (Or Gson) You can get Posts and Many more stuff From Your site/Blog.
That's the Easiest way to do that I Think.

Posting to a wall of a facebook user using the graph api

i am new to facebook app development and i am trying to post a simple text on the wall of the user using the https://graph.facebook.com/me/feed?access_token=ACCESS_TOKEN&message=hello but this does not seem to be working..Any thoughts as to where i might be going wrong?
Check if you have permissions to post from the app.
Add app_id to your call.
If you’re just calling the URL you mentioned, that would be a GET request. To post a message to the user’s wall you have to use method POST. You can test it in the Graph API Explorer – change the method to POST via the dropdown, click „add a field” and use name=message and value=your_message …

How to retrieve home timeline from twitter in the form of .xml or JSON using java?

I want to get a home timeline from twitter and I was able to get the home timeline using twitter4j and oauth authentication method
ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder.setOAuthAccessToken(accessToken.getToken())
.setOAuthAccessTokenSecret(accessToken.getTokenSecret())
.setOAuthConsumerKey(key)
.setOAuthConsumerSecret(secret);
Twitter twit = new TwitterFactory(confBuilder.build()).getInstance();
User user = twitter.verifyCredentials();
List<Status> statuses = twitter.getHomeTimeline();
but the result is not in the form of .xml or JSON. i also tried
WebResource resource = client.resource("https://api.twitter.com/1/statuses/user_timeline.json");
but all I get is GET https://api.twitter.com/1/statuses/user_timeline.json returned a response status of 401 Unauthorized
I googled many times but I just cant get it right. Please I need a sample java code of how to do it. Complete code that can run right away would be really helpful as I got a lot of partially coded program and just couldnt get it to work. thank you in advance
OK, so after looking at the release notes for the 2.2.x versions, it appears there is a way to get the JSON representation from Twitter4J, but it's disabled by default since it uses some extra memory.
So, you need to:
Enable the JSONStore using the jsonStoreEnabled config option
Get the JSON representation of a request using the getRawJson method
Sorry there's no code example, I haven't tried it myself.
401 Unauthorized:
Authentication credentials were missing or incorrect.
You need to authenticate before you perform the query.

Categories