how to share to facebook without showing feed dialog in android application? - facebook

I tried a lot about sharing to facebook without showing dialog using facebook android sdk,but could not get solution. Please help me to share to facebook without dialog.

Use GraphReqest. This code posts a Bitmap image on facebook with caption using facebook sdk 4.2
Bitmap bmp;
String caption;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
final JSONObject graphObject=new JSONObject();
Callback callback=new Callback() {
#Override
public void onCompleted(GraphResponse response) {
// your code
}
};
GraphRequest request=GraphRequest.newPostRequest(AccessToken.getCurrentAccessToken(), "me/photos", graphObject, callback);
Bundle params = new Bundle();
//params.putString("method", "photos.upload");
params.putString("caption", caption);
params.putByteArray("picture", byteArray);
request.setParameters(params);
request.executeAsync();
You will have to take publish_actions permissions from the user
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
Moreover, If your app requires publish_actions, then you also need to send your app for the review on fb developers page, otherwise it will only work for developer accounts and tester accounts.

Related

Sharing screenshot with text to facebook unity

I'm trying to give the user the possibility to post a screenshot of his game on facebook with the dowload link of the game.
I've looked a bit and it seemed it would be possible with FB.API, but I can't manage to make it work.
Aparently you need a permission but I can't to find which permission and how to give it.
I'm using unity 2020.3.21f1
Here is what I'm doing for now
public void ShareScreenShot(Texture2D screenShot)
{
byte[] encodedScreenShot = screenShot.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", encodedScreenShot, "ScreenShot.png");
wwwForm.AddField("message", "Venez me défier : https://randomlink.blablabla");
FB.API("me/photos", HttpMethod.POST, ShareScreenShotCallback, wwwForm);
}
void ShareScreenShotCallback(IResult result)
{
if (result.Error != null)
{
Debug.Log(result.Error);
}
else
{
Debug.Log("sharing success");
}
}
If anyone of you knows how it can be done, it would be of great help, thanks
I suppose you need to login to facebook with custom permissions, because the default one only allows you to send invitations to choosen friends.
https://developers.facebook.com/docs/unity/reference/current/FB.LogInWithPublishPermissions/

Is FB App Review necessary for read only website?

I'm creating a website which show a single Facebook page content in the homepage (events basic informations, photos and the five latest instagram photos). Do I have to submit an App Review? If yes, what permissions do I need?
There is no FB login request in the site and no content is published using it. No FB/Instagram user information is shown.
Thanks,
Alessio
EDIT:
Here is my code. It's the same for every endpoint
function loadFacebookEvents(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
fbEvents=JSON.parse(this.responseText).data;
renderFacebookEvents()
//loadFacebookPhotos()
}
};
//events
xhttp.open("GET", "https://graph.facebook.com/thecagelivorno/events?time_filter=upcoming&fields=cover,description,end_time,name,start_time,ticket_uri,place&access_token=<my-access-token>", true);
xhttp.send();
}

Get profile Facebook photo without access token

I am trying to get users profile photo using facebook graph
I thought photos were public and you do not need to have an acces token but when trying I receive A question mark photo.
Trying with my Id
http://graph.facebook.com/10150172705012177/picture
returns a blue question mark, by the graph explorer I get access token and I Have the photo
http://graph.facebook.com/10150172705012177/picture?access_token=xxxxxxx
Can I get the profile photo with the fb id without access token???
With:
FB.API("10150172705012177/picture", HttpMethod.GET, delegate(IGraphResult photoResult)
and With
public static IEnumerator GetFBProfilePicture()
{
WWW url = new WWW(System.Uri.EscapeUriString("https: //graph.facebook.com/" + 10150172705012177 + "/picture?type=large"));
yield return url;
Debug.Log("Completed.");
Texture2D texture = new Texture2D(180, 180, TextureFormat.DXT1, false);
url.LoadImageIntoTexture(texture);
// ...
var image = Canvas.FindObjectOfType<Image>();
image.overrideSprite = Sprite.Create(texture, new Rect(0, 0, 8, 8), new Vector2(0.5f, 0.5f)); ;
}
I receive the same, a red question mark
Resolved!!
I just was getting the id photo and not my Facebook Id
With my facebook Id works :D

facebook 3.5sdk open graph Explicitly Share

I'm trying to get my OpenGraph action to the news feed, and I learned that for that I need to add the ExplicitlyShared Capability to the Facebook app's OpenGraph action settings, and I did. Yet when I put it in my code, like this:
OpenGraphObject model = OpenGraphObject.Factory.createForPost("origame_app:model");
model.setProperty("title", modelname);
model.setProperty("url", "http://samples.ogp.me/1386546688246429");
model.setProperty("description", modeldesc);
Bitmap bitmap = decodeSampledBitmapFromUri(filepath[position], 500, 500);
List<Bitmap> images = new ArrayList<Bitmap>();
images.add(bitmap);
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("model", model);
action.setExplicitlyShared(true);
#SuppressWarnings("deprecation")
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "origame_app:fold", "model")
.setImageAttachmentsForObject("model", images, true)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
I get an error. But otherwise the OpenGraph works great. What's the problem?
I was also dealing with this issue and finally, I found a workaround. Instead of calling
action.setExplicitlyShared(true);
use
action.setProperty("explicitly_shared", true);
I reported this bug to Facebook: https://developers.facebook.com/bugs/559486710849474/.

Logging out from facebook using facebook c# sdk in WP7

I want to implement logout from facebook using facebook C# sdk in my windows phone app
My primary question is how do we logout using Facebook C# SDK in WP7
I found this article in search
Article link
there he is trying to find the logout url using regex, but that did not working in my app
when i try that the browser navigated event is going into infinite loop
you can share any samples/posts related to facebook logout in windows phone 7.
I want logout should happen with out user intervention, after he clicks on a button he should looged out from facebook and from next time he should see the login page
I tried following posts/blogs also but no use.
LINK 1
LINK 2 this giving error while splitting the accesstoken
UPDATE
LogOutButtonCode
FacebookClient _fbClient = new FacebookClient(fbaccess.AccessToken);
var logoutParams = new Dictionary<string, object>();
logoutParams.Add("next", "https://www.facebook.com/connect/login_success.html");
//logoutParams.Add("",)
var logoutUrl = _fbClient.GetLogoutUrl(logoutParams);
BrowserControl.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(BrowserControl_Navigated);
BrowserControl.Navigate(new Uri(logoutUrl.AbsoluteUri));
Navigated Event CODE
if (e.Uri.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
e.Uri.AbsoluteUri returns https://www.facebook.com/home.php
Logout URL i am getting from the server https://www.facebook.com/logout.php?next=https://www.facebook.com/connect/login_success.html
Use FacebookClient.Logout to generate the logout url.
This is the snippet from winforms sample which will work in wp7 with some modifications.
private void btnLogout_Click(object sender, EventArgs e)
{
var fb = new FacebookClient();
var logoutUrl = fb.GetLogoutUrl(new
{
next = "https://www.facebook.com/connect/login_success.html",
access_token = _accessToken
});
var webBrowser = new WebBrowser();
webBrowser.Navigated += (o, args) =>
{
if (args.Url.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
Close();
};
webBrowser.Navigate(logoutUrl.AbsoluteUri);
}
Make sure to persist the access token somewhere when you login as it is required to logout.