how to post a picture to user group using facebook4j api using facebook groupid - facebook

How to post a picture to user group using facebook4j api using facebook groupid.
PostUpdate post = new PostUpdate(new URL("projectUrl")).picture(new URL("projectUrl/waz24.jpg")).name("Facebook4J - A Java library for the Facebook Graph API");
facebook.postGroupFeed(getId, post);
above code not showing image it shows some symbol.

Use this for sharing photo with link and description.
PrivacyParameter privacy = new PrivacyBuilder().setValue(PrivacyType.ALL_FRIENDS).build();
PostUpdate postUpdate = new PostUpdate(new URL("http://facebook4j.org"))
.picture(new URL("http://facebook4j.org/images/hero.png"))
.name("Facebook4J - A Java library for the Facebook Graph API")
.caption("facebook4j.org")
.description("Facebook4J is a Java library for the Facebook Graph API. This library provides the ease of use like Twitter4J. Facebook4J is an unofficial library.")
.privacy(privacy);
String postId = facebook.postFeed(postUpdate);
Thanks..

Related

How to get Instagram post URL from Facebook Graph media_id

I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.
I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.
Is there a way to get Instagram Post URL with FB Graph API media_id?
It seems like you can get media metadata (and all comments/replies) when someone #-mentions you in a non-owned-media comment by using a query like below.
You would use your own instagram business account id for the first number (the path component), and you'd use the comment_id you received from the webhook comment-mention notification as the second number:
/12345678901234567890?fields=mentioned_comment.comment_id(9876543210987654321){id,text,username,timestamp,media{id,media_type,media_url,permalink,username,like_count,comments_count,comments{id,text,username,user{id,username},like_count,timestamp,replies{id,text,username,user{id,username},like_count,timestamp}}}}
Yes, there is a way you can get Instagram post URL associated with a media if you know the media id.
You can also get more information (all its fields and edges) on media. See the docs here
You can get the Instagram post URL by making a GET request to /{ig-media-id}
Sample Request:
GET https://graph.facebook.com/v15.0/{{media_id}}?fields=permalink, shortcode&access_token={{ACCESS_TOKEN}}
Sample Response:
{
"permalink": "https://www.instagram.com/p/Clxsi5Pol2_/",
"shortcode": "Clxsi5Pol2_",
"id": "17xxx59557977xxx"
}
The value of the permalink is the valid public URL for the post.
You can also use the shortcode returned to construct the URL by concatenating the shortcode to https://www.instagram.com/p/.

Facebook Graph API post message with link to page's wall

My problem is: When I post to page's wall some message with link it shows as Posted By Others, without link it shows normally in page timeline (Im group's admin ).
The same code posts to my timeline just fine:
I use AS3 library.
My permissions:
"publish_stream", "user_photos","publish_actions","manage_pages"
my post code:
var params:Object = new Object();
params.message = messageTextInput.text;
params.description = "description";
params.caption = "caption";
params.name = "name";
params.link = "http://www.ya.ru";
params.picture = "http://image.bayimg.com/cajchaado.jpg";
FacebookDesktop.api(page.id+"/feed", onCallApi, params, "POST"); //use POST to send data (as per Facebook documentation)
Facebook documentation says I can post either link or message, but it works just fine, except of showing in "Recent posts by others" ( please see attached screenshot ).
To post on a fanpage on behalf of itself (not the user), you have to use the page access token.
What happening is- when you make the call, the sdk uses the default token (user token), so the post is published on behalf of the user which is displayed in the "Recent Post by Others" section in the page.
Since you have requested for manage_pages already in your code, you can simply obtain the page access token with this call- /{page-id}?fields=access_token. Use this token with your current call just by adding the parameter access_token-
....
params.picture = "http://image.bayimg.com/cajchaado.jpg";
params.access_token = "{page-access-token}";
....

Read Facebook Post

I am writing a web application using c#.net 4.0 to read post in a specific Facebook page.
E.g. http://www.facebook.com/pages/Public-Service-Association/164106710269112
I used Facebook C# SDK from http://github.com/facebook/csharp-sdk/
Please help me to read the posts using above SDK?
Thanks.
After you follow the tutorial, after you declare a JSON for your results, simple get their Profile Feed:
Facebook.FacebookAPI api = new Facebook.FacebookAPI(token); //place your access token
JSONObject result = api.Get(#"/nzpsa/feed");

How to get AppID based on valid AccessToken and/or Facebook.FacebookClient object

I'm logged in using to my own Application using C# Facebook SDK and I can read/write/delete all data I need.
However for validation purposes I'd like to get AppID that I'm currently using (the one I used when generating login Uri) based on existing valid Access-token and Facebook.FacebookClient object.
In a similar way like in Facebook PHP SDK: $appId = Facebook->getAppId();
My access token is not like string.Concat(appId, "|", appSecret)
If I use Facebook C# Sdk I may use following code to retrieve appID I used when loging in - if at the moment I have in memmory only AccessToken available:
string myAccessToken = "...";
FacebookClient fc = new FacebookClient(myAccessToken);
IDictionary<string, object> resultContainer =
(IDictionary<string, object>)fc.Get("/app");
string retrievedAppID = resultContainer["id"] as string;
The same result can be obtained directly from Graph Api Explorer via:
https://graph.facebook.com/app
If desired Facebook application is selected at top right part of the Graph Api Explorer page.
In the Facebook C# SDK, there is no where that access_token parses(or decoded).
Naturally, Facebook C# SDK api, it takes appId from Web.Config through the FacebookSettings class.
access_token as string property of FacebookSignedRequest class.
So you may follow this link to do it yourself: https://developers.facebook.com/docs/authentication/signed_request/
You should be able to get the AppId like this:
var appId = Facebook.FacebookApplication.Current.AppId;

Facebook Graph API - "Related Post" in status update

In the Facebook UI, you can hit "#" when you update your status and get a list of pages where your status update will be added as a Related Post on the page.
Is there a way to do the same in the Graph API? Assuming all authenticated, calling me/feed with a "message" parameter like this (using .NET Facebook SDK):
var client = new FacebookClient(ACCESS_TOKEN);
var parms = new Dictionary<string, object>();
parms.Add("message", "TEST fb SDK: #whatever");
client.Post("me/feed", parms);
The status update is posted, but the page doesn't doesn't get resolved as a Related Post.
If you GET a feed entry which has a Related Post created from the UI it's shown as a status update with the "to" parameter populated with the page. If you recreate that message as a POST in the API, the Related Post gets created, but:
the Related Post shows on the Info tab of the page, not the Related Posts tab
the status update doesn't have a link to the Related Post
Any thoughts? Thanks!
Someone has posted an undocumented way of tagging users using Facebook Graph API that involves using a #[{user_id}:1:{name}] syntax, eg: #[{4}:1:{Mark Zuckerberg}]. There is an open request with Facebook for full documented support of this method.