Delete image from facebook album - android

I'm developing app which post images to facebook. That's working quite good. But my problem is that i can't find sample that would delete selected photo from facebook. I have allready made an function that gets the WallId and PhotoID from facebook.
My problem is that i can't get what should i put in facebook runner.request i know that i need to pass DELETE and PhotoId my function currently is
private void delete_fb(){
AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook);
Bundle params = new Bundle();
params.putString("fields", "id,name");
if(favi.get(indeks).fbid!=0 && WallId != 0){
fruner.request("me/"+WallId+"/"+favi.get(index).fbid,params ,"DELETE",new Del(),null);
}
}
So if you could explain me what to put in place of "me/"+WallId+"/"+favi.get(index).fbid in fruner.request() or give me some example code i would be very pleased.
Thank you.

try this
fruner.request(YourPostId, params ,"DELETE", new Del(), null);

Related

Add profile picture to contacts in Xamarin.Android

I am creating a hybrid mobile app, using Xamarin.Forms.
I want the user to click a button and the contact in the app gets inserted into the phone's contacts, including the profile picture.
So far, everything on the iOS side is working. I successfully insert the profile picture.
I can't get it to work on Android though. I've already tried looking on here but all solutions use Java. Inserting the name, number and e-mail works perfectly.
Here is my code so far:
public void SaveContacts(string name, string number, string email, string job, string company, byte[] imageData)
{
try
{
var intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.ContentType);
if (!string.IsNullOrWhiteSpace(name))
intent.PutExtra(ContactsContract.Intents.Insert.Name, name);
if (!string.IsNullOrWhiteSpace(number))
intent.PutExtra(ContactsContract.Intents.Insert.Phone, number);
if (!string.IsNullOrWhiteSpace(email))
intent.PutExtra(ContactsContract.Intents.Insert.Email, email);
if (imageData.Length != 0)
{
// INSERT PROFILE PICTURE HERE
}
Platform.CurrentActivity.StartActivity(intent);
}
catch (Exception ex)
{
DependencyService.Get<ILogger>()?.Error(ex);
}
}
How do I add the profile picture to the contact?
According to this case which is about Insert Contact (ContactsContract) via Intent with Image (Photo), you need to use the intent.putParcelableArrayListExtra(Insert.DATA, data) method to add the photo to the new contact.
But I have create a sample to test it. This method have a bug. I use the following code:
List<ContentValues> data = new List<ContentValues>();
ContentValues row1 = new ContentValues();
Intent intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.Photo);
intent.PutParcelableArrayListExtra(ContactsContract.Intents.Insert.Data, data);
But it will show the type convert error. Even though the class ContentValues is inherited from the IParcelable interface. The error still show. You can report it to the xamarin on the github.
In addition, I also try to use the method about using the content provider to insert a contact. But the RawContacts doesn't have ACCOUNT_TYPE property.
So for the bug, it seems you can't add profile picture to contacts with the native api.

Is GraphObject can be used with ShareDiaog in android

I've used GraphObject to share user story here is my object.
Bundle params = new Bundle();
params.putString("reward", permaLink);
params.putBoolean("fb:explicitly_shared", true);
GraphRequest request = new GraphRequest(
MainActivity.getInstance().mSimpleFacebook.getAccessToken(),
"me/rewardster:redeem",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i(TAG, graphResponse.toString());
}
}
);
request.executeAsync();
It works fine, is it possible for me to share it via ShareDialog, so user can add text to it or tag someone from friend list. etc?
If my current code is not good with share dialog please help me translating my graph object to some other model which is compatible with share dialog.
Its possible in IOS by the way.
There must be some way out of it in android as well.
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"rewardster:redeem";
[action setString:rewardObj.fbStoryLink forKey:#"reward"];
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"reward";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
NO, if you use share dialog you cant customize much[there is few flexibilty], hence to customize the post as a story and add custom fields and to modify the post we use graph stories check out the link https://developers.facebook.com/docs/sharing/opengraph. Both allows you to share but the post will look different.
to create a custom graph story refer this link
https://developers.facebook.com/docs/sharing/opengraph/custom
To achieve those custom things that you have asked you need to use graph-api only

me/friends empty friend list

I am trying to get friend list using me/frineds tag. There is no user of the app so far so i have added some frirneds as a tester of the app. But they are not showing in the response i am getting empty data list. Please guide me what i am doing wrong here. Here is the code
Bundle required = new Bundle();
required.putString("fields", "id, name, picture.type(square), gender, email");
//Request for friendlist from facebook
Request req = new Request(session, "me/friends", required, HttpMethod.GET,
new Callback() {
#Override
public void onCompleted(Response response)
{
is2=response.getGraphObject();
JSONObject json = is2.getInnerJSONObject();
readResponse(json);
String str = json.toString();
saveFileOnSD("data", str);
// generateNoteOnSD("frinedresponse", str);
Log.v(TAG, str);
}
});
Request.executeBatchAsync(req);
With v2.0, only users who are using the App too show up in the friend list. It is not enough to add someone as Tester in the App Settings, a user has to authorize your App.
See changelog for more information: https://developers.facebook.com/docs/apps/changelog
There is also "invitable_friends" and "taggable_friends", the first one is for game invitations only and the second one is for tagging only.
This has been previously asked, and the thread listed below has a ton of details. The only work around is if your app is a game. Here is the link to the other post: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Android & Facebook SDK : decoding pictures from /me/picture graph call

EDIT: Anwser at the end of this post.
I am trying to get a Facebook user's profile picture thanks to the inbuilt Facebook SDK's function Request().
I am using a /me/picture call to get the profile picture and convert it into a Bitmap.
The call is working fine but I don't know how to interpret and parse the result returned from Facebook
Here is the JSON that I get:
{
"FACEBOOK_NON_JSON_RESULT" : "����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000\u0004*\u0000��\u0000C\u0000\u0006\u0004\u0005\u0006\u0005\u0004\u0006\u0006\u0005\u0006\u0007\u0007\u0006\b"
}
I think this should be representing the profile picture but I don't know what to do with this now.
If somebody could tell me either how to decode it, convert it to a Bitmap or what kind of data it is, I would be grateful.
NOTES: I don't want to use any other function than Request(), like DecodeStream() or an AsyncTask
Here is the answer:
When making a new Request() you need to add the "redirect" parameter to false:
Bundle params = new Bundle();
params.putBoolean("redirect", false);
This will return the correct picture URL:
{
"data":{
"is_silhouette":false,
"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xpa1\/v\/t1.0-1\/p100x100\/10312434_10152395442477210_2933994167675146084_n.jpg?oh=f3c8cb920c97fcfa4dc5e17462445cbf&oe=54404A3A&__gda__=1412730795_5f288e34e5f6e63cb1c3791dcb142880"
}
}
Try this :
ImageView user_picture;
userpicture=(ImageView)findViewById(R.id.userpicture);
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);
Where ID is one your profile ID.
For Further details check this :
https://developers.facebook.com/docs/graph-api

Facebook - Android - Total Likes - Graph API

I'm attempting to retrieve the total number of likes for a selected Facebook Page POST
According to this page:
How to get Likes Count when searching Facebook Graph API with search=xxx
I've tried to refer to the answers in that post and to build my code based on that.Here's the current code that I have based on it
private void totalLikes(String post_id){
Bundle bun = new Bundle();
bun.putString("summary","true");
new Request(Session.getActiveSession(), post_id+"/likes/",bun, HttpMethod.POST,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast.makeText(getBaseContext(),String.valueOf(response),Toast.LENGTH_SHORT).show();
}
}).executeAsync();
}
Unfortunately the response given is not what was expected,I was thinking that it could be due to my Bundle parameters.So I would like to know what are the actual bundle parameters I should be putting for the code?Thank you for the help :)!
In your Bundle string addition, try changing it to bun.putString("fields","likes.summary(true)"); and change the graph path to just the post_id. There should end up being a "summary" field in the response after that.
EDIT: Here's another method that might work better with permissions.
Graph path: post_id + "/likes"
with
bun.putString("include_summary", "true");
I tried messing around in the explorer and couldn't get it to work, but you might have better luck.

Categories

Resources