Facebook: post a photo on a friend's wall - java

I'm trying to post a photo on the wall of a friend using RestFB, a Java API for Facebook. I tried various solutions like:
facebookClient.publish(fbu+"/photos/",FacebookType.class,new FileInputStream(pathOrig));
fbu is the Facebook user id of the friend. This code actually posts the photo on my wall!
facebookClient.publish(fbu+"/feed/",FacebookType.class,new FileInputStream(pathOrig),Parameter.with("message",message));
This code posts the message on my friend's wall, but without the photo.
Strangely, it's possible using directly Facebook to upload photos on friends wall, so it should be possible using Graph, in my opinion...
Any clue?

You can't post a photo on your friends wall. You can, however, upload a photo and tag your friend in it.
According to the Photo Documentation you set the tags on a photo by setting the tags parameter on the graph request, and formatting like so:
[{
"tag_uid": <fb uid>,
"x":74,
"y":62
},
{
"tag_uid": <fb uid 2>,
"x":8,
"y":27
}]
Each object is the has your friend's FBuid and the x and y position of the tag location on the photo.
You can, however, publish a link on your friend's wall to a photo and have the link go off Facebook for them to view it. This is probably not what you're looking to do, but it's an option.

Related

Get all photos from posts on a Page

I have the necessary permissions from facebook. I am using RESTFB, I see the methods getFullPicture and getPicture in Post.class but unable to make anything out of it. How to get all the photos from a post on a page in FB, using RESTFB in Java.
GetFullPicture and getpicture are not meant to give all images. To get the images from a post we have to get the post ID. Post id is the combination of pageId and one of the photo's which user has uploaded in that post, that photos id.
Example:242343423_2423423423. So the second part is a photo id. Take that photoId and query for its album. 2423423423?fields=album. will give the albumId. Get all photos from that album. JobDone!

Programmatically get like count of a photo from Facebook using java

I am developing an andorid app which post some photo on Facebook, at the same time I want to calculate the number of likes of that photo from my android app.
For information -
I am using Facebook SDK and I have successfully logged in Facebook account and posted the image.
The method which post image is below
private void PublishImage()
{
Bitmap image = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
//Here we set all the required parameters to share the image and build that
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setCaption("Testing Sharing Feature through java")
.build();
//Now we share the PhotoContent by adding the properties in instance of SharePhotoContent
share = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
//Now we use share API to share the image
ShareApi.share(share,null);
}
How to calculate the number of likes of posted photo with java instead of using Graph API Explorer manually ?
I don't think you can do that without the graph API. Once you call ShareApi.share (), there is actually a graph API request which uploads the photo, and you will get likes from various platforms, your app has no way of knowing how many likes have been posted

Facebook share image sharedialog

I'm sharing an image with my app, and the code is this:
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(Show.this)
.setDescription("xxxxxxxxxxxxxxxxxxxxxxxxx!")
.setApplicationName("appname")
.setPlace("me/photos/")
.setPicture(imagesURL+imageFileName)
.setLink("https://play.google.com/store/apps/details?id=x.x.xxx")
.build();
everything is fine, but the image is getting shared small-sized on the side of the link, and not into the user's profile, what should i do to share it like a normal "big" photo?
Also, if i take the
.setLink(xxxxxxxxxxxx);
the image isn't shared at all..
What I think is that in your setLink() function you are giving the link of the page not the image resource.
For example if you have an image link like this .
http://blog.delicious.com/wp-content/uploads/2013/07/facebook_logo.jpg
now as this is the link to the image resource on the server, If you use it in the setlink function
setLink("http://blog.delicious.com/wp-content/uploads/2013/07/facebook_logo.jpg");
You will get the big Image.

Android - Get a contact's Facebook picture

Android platform is really fun to work with especially when it comes to resolving issues. Indeed, there is possibly everything there is to know about Android development on the internet.
Alright, I've been searching for about a week and haven't found anything that was close from working. Let's dive into it.
We are building an Android Application that requires a read/write access to existing Contacts on a device. It has become really easy to read a contact's set photo using this method :
// Returns a stream reading a contact thumbnail
public InputStream getContactThumbnail(int id) {
// Stream reading contact image
InputStream stream = ContactsContract.Contacts.openContactPhotoInputStream(
context.getContentResolver(),
ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, id
)
);
// If image is null, try to read Facebook image
if (stream == null) {
stream = new ByteArrayInputStream(getFacebookPhoto(id));
}
return stream;
}
Now, the previous method receives an id as a parameter and returns a Stream making it possible to read the contact's thumbnail. It is needed to be a stream because the phone acts like a web server and has multiple threads running. If a thumbnail is requested several times in the same short time lapse, an OutOfMemoryException will be thrown for sure.
I need to correctly implement the getFacebookPhoto(int) method so that it returns whatever stream reading the Facebook profile picture of a contact that has his or her contact linked with his or her respective Facebook profile. I've tried and failed so many times.
Hypothesis #1
If a contact is linked with a Facebook profile, it has to have the Facebook ID saved somewhere. If this information is accessible, it would make it easy to get a Facebook profile picture using graph. Problem is an internet connection is needed to do so.
Hypothesis #2
Facebook thumbnails are saved somewhere on the SD card. Maybe there's a link between a Contact and those files that can be found through an SQLite request?
Hypothesis #3
sigh, I look desperate. Okay, if I understood correctly, a phone Contact and a Facebook Contact are not the same things in the database. If you query all the contacts from the following URI :
*ContactsContract.Contacts.CONTENT_URI*
you only get contacts that you created and nothing regarding Facebook links. Is there a way to find all linked contacts and get their respective photos?
Conclusion
Yeah, that's about is. To sum it up, I need to read all contacts information. For each contact, I have to find its photo. If the user has not set a picture to a contact that is linked to a Facebook profile, the profile picture which it was linked too must be read.
Up until now, the StackOverflow community has been of a great help and saved my life and job countless times. It is possible, I've seen it in other apps.
Thank you for spending of your time, it is truly appreciated.
EDIT
Let's not give up! I will start a 100pts bounty as soon as I can.
Your hypothesises are right to a certain extend. In contact application this things are handled as folows -
Device's Contact & its Facebook account are mapped by Contact's _ID & Facebook's id, this is one-to-one mapping. So from this mapping first you have to find out the Facebook id
of the conserned contact. But in which table this info is stored & wheather that table is eposed to you or not, URL to that table completely dependent on vendors.
From Facebook Id we can get corresponding profile image either from Facebook's server or from Media DB, if it is also cached in.
But this is not supported by all OEMs. And implementation varies from OEM to OEM as Google don't enforce for any common standard implementation of it.
So there is no garantee that a single implementation will work for all devices from different OEMs.
You should really go and play around with Graph Explorer on the Facebook Developers site it will help you a lot in figuring out what you need to do to get certain things. In order to get the picture for an person you just have to do is do a simple GET HTTPRequest with the graph path of /ID?fields=picture (where ID is the facebook id of the contact) which will return a JSON object that contains the link to that person's profile picture. From there it should be fairly simple for you to get the image.
You can also do the same thing to get all of a person's friends with the picture information by sending a GET request to /me/friends?fields=picture. It seems like you are trying to avoid a web connection but if the android contacts do not store the facebook id then you will have to get the ids yourself I'm afraid.
Hope that helps.
Why don't you use FQL, for Android you can use -
String query = "SELECT uid, name, pic, pic_small, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new CustomRequestListener());
where CustomRequestListener() extends RequestListener in the Facebook Android SDK.

Facebook clipping text on Android when using an ACTION_SEND intent

I have added code to my casual game to share highest score through social networks, email, etc.
This is the text I send as defined on strings.xml resouce, for l10n:
<string name="game_sharing_score" formatted="false">
My new High Score on Gamename: %d\n
You can download Gamename from here:\n
https://play.google.com/store/apps/details?id=gamepackage
</string>
Please, note that Gamename and gamepackage are not the actual ones that I am using.
The code for sharing is the following one:
String shareScoreMsg = String.format(context.getString(R.string.game_sharing_score), highestScore);
Intent shareScoreInt = new Intent(Intent.ACTION_SEND);
shareScoreInt.setType("text/plain");
shareScoreInt.putExtra(Intent.EXTRA_TEXT, shareScoreMsg);
game.startActivity(Intent.createChooser(shareScoreInt, context.getString(R.string.game_sharing_score_title)));
game is an Activity, context is an Application context, game_sharing_score_title is the title of the activity "Share your score". Anyway there is no problem with the code it self, it is working fine for sharing through Google+, WhatsUp or Twitter, but when the user selects to share through FaceBook, the text is clipped and it publish only the last link, with the information and one icon image that FB gathers from Google Play, ignoring all the text before the link.
It is pretty clear that the problem is just with Facebook, no with the code or the string.
What I would like to find is some kind of workaround, if exists, to avoid these FB problems. To be honest, I do not like Facebook, but it is a social network with millions of people and I cannot simply ignore it on my game.
Thanks a lot in advance,
Create Facebook app on your account
After that, you get the App id.
Access all methods from Facebook API.

Categories

Resources