Sharing screenshot with text to facebook unity - facebook

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/

Related

Preview is not available in sharing to Facebook with Firebase Dynamic Link

I have created a shorten dynamic link with Firebase. When I share the link to Facebook, the preview is not available. I have tried with the long link. It's not working either. I have provided the link with metadata. But is is not showing the preview.
This is the code I am using now.
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse(longLink))
.setIosParameters(new DynamicLink.IosParameters.Builder(getPackageName()).build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder(getPackageName()).build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setImageUrl(Uri.parse(demoPhoto))
.setImageUrl(Uri.parse(itemsVO.getThumbnail().get(0)))
.build())
.buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
// Short link created
Uri shortLink = task.getResult().getShortLink();
itemsVO.setShareLink(shortLink.toString()+"?d=1");
shareBtn.setVisibility(View.VISIBLE);
} else {
// Error
Toast.makeText(this, "Error in creating dynamic link", Toast.LENGTH_LONG).show();
// ...
shareBtn.setVisibility(View.GONE);
}
});
Can anyone tell me why it is not working?

Is there any way to specify facebook-links with the HTTP protocol which opens the app (iPhone/Androdi) if installed?

So I know the Facebook-app supports the fb:// URL scheme. But does it also support a URL scheme for HTTP?
I've tried for instance https://www.facebook.com/Google, and it does not yield an option to open the app, when clicked on from Chrome on an HTC One M8 device. So obviously Facebook haven't defined a URL scheme to match that URL. But they might have created others? Theoretically they could for instance have a scheme that triggered when a sub-url contains /app or something.
My goal is to link to a Facebook profile page which opens in the app if it is installed, and in the browser if not. Without using any Javascript. If facebook have defined a schema matching any HTTP-protocol, it is possible.
I made this work for link to google play with this function, changing te protocol to the facebook could work
public void getpro(View view) {
final String appName = BuildConfig.APPLICATION_ID;
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName")));
}
}
to:
public void getpro(View view) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("facebook://facebook.com/inbox")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com")));
}
}
You can try to achieve this with Intents. I found this:
String uri = "facebook://facebook.com/inbox";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Intent is used to call other applications while using an application.

Social providers integration in Xamarin.Android

I just trying to add add the Facebook integration with my app in Xamarin.Android. For that I found that there is a Component named as Xamarin.Social then I am trying that. Here is my attempt.
Attempt :-
void btnShare_Click(object sender, EventArgs e)
{
try
{
var facebook = new Xamarin.Social.Services.FacebookService()
{
ClientId = AppId,
RedirectUrl = new System.Uri("http://www.facebook.com/connect/login_success.html")
};
// 2. Create an item to share
var item = new Item { Text = "Xamarin.Social is the bomb.com." };
var shareController = facebook.GetShareUI(this, item, result =>
{
if (result.HasFlag(Xamarin.Social.ShareResult.Done))
{
Toast.MakeText(this, "Posted", ToastLength.Long).Show();
}
if (result.HasFlag(Xamarin.Social.ShareResult.Cancelled))
{
Toast.MakeText(this, "Cancelled", ToastLength.Long).Show();
}
});
StartActivity(shareController);
}
catch (Exception exp)
{
}
}
Note :- Facebook login page is opening successfully.
Error :- But I am getting this Forbidded(403) error. the point is this error is not reaching to catch block , but it is shown in a toast notification. so no further details are available.
Does anybody explored this component successfully ?
Any help is appreciated :)
As I mentioned in the comments, I had to many issues using the social plugin, I just used the android share intent, see example below
var shareIntent = new Intent();
shareIntent.SetAction(Intent.ActionSend);
shareIntent.PutExtra(Intent.ExtraText, message); //message is the text you want to share
shareIntent.SetType("text/plain");
StartActivity(shareIntent);

Share image on Facebook

WP8 how to share data from my app to Facebook
or twitter
i want to take screen-shoot of my list-box and then share it on Facebook
i try this code
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "Code Samples";
shareLinkTask.LinkUri = new Uri("https://www.facebook.com/", UriKind.Absolute);
shareLinkTask.Message = "Here are some great code samples for Windows Phone.";
shareLinkTask.Show();
but it doesnot work
You should not use ShareLinkTask for sharing photos. You should use ShareMediaTask. You can more information and how to implement ShareMediaTask by clicking link I provided herewith.
Here's the code:
CameraCaptureTask cameraCaptureTask = new CameraCaptureTask();
//declare it globally
cameraCaptureTask.Completed += cameraCaptureTask_Completed;
//declare it in Constructor
cameraCaptureTask.Show();
//declare it in any method.
For example, button click event. By using this method, you can capture the list box.
//declare this method anywhere in the cs page
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if(e.TaskResult == TaskResult.OK)
{
ShowShareMediaTask(e.OriginalFileName);
}
}
void ShowShareMediaTask(string path)
{
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = path;
shareMediaTask.Show();
}
Now, You can easily take screenshot of app's listbox and share it with any of the social networks where user installed on their phone. Cheers.!

Facebook action script 3 API login/logout issue

I'm making mobile AIR app for Android using Flash builder 4.5, AIR 2.6, Facebook action script 3 API the latest version.
I have a problem with login/logout. I can login only one time - then my data caches somehow and Facebook automatically logs me in. When I call logout I receive response TRUE, but I don't really logout from system. Standard login dialog doesn't appear for me. I have already read a lot of articles on stackoverflow and open issues on official site, but none of them were helpfull. How can I solve this? Here is the code I use:
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.external.ExternalInterface;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.Security;
import flash.display.Loader;
import com.facebook.graph.FacebookMobile;
public class TestProj extends Sprite
{
public function TestProj()
{
super();
//register to add to stage
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
FacebookMobile.init("195053007196177", initCallback);
}
private function initCallback(success:Object, fail:Object):void
{
var appPermissions:Array = new Array("read_stream", "offline_access", "publish_stream", "read_friendlists");
FacebookMobile.login(loginCallback, this.stage, appPermissions);
//FacebookMobile.logout(logoutCallback);
}
private function loginCallback(success:Object, fail:Object):void
{
//And here I always receive success with my UserID
//and login dialog don't appears to me before this
if (success)
{
trace("login ok");
}
else
trace("login failed");
}
private function logoutCallback(success:Object):void
{
//here I reseive "TRUE" always!!
trace(success);
}
}
}
You're only passing the 1st argument of logoutCallback to your logout method. If you add in the 2nd argument of your site url specified for your app, it should clear it out the html cookie for that window. Also, set FacebookMobile.manageSession = false;
FacebookMobile.logout(logoutCallback, "http://your_app_origin_url");
There is a potential, related bug that involves Desktop and Mobile not accessing or clearing the access token's the same way. For that, there's a hack that describes exposing the access token in FacebookMobile, then manually calling the "logout" method with the access token. The issue is described here, including a method called "reallyLogout". If what I've written above doesn't work, implement "reallyLogout".
When you log out, your app clears the local session but does not log you out of the system. This is clearly defined in the documentation for logout. Think about it, if you're logged into Facebook on your Smartphone, Web Browser, and now this Mobile Desktop App, and suddenly you log out... it shouldn't log you out EVERYWHERE, just within that browsers session. So pass that 2nd parameter.
I've had this exact problem, and after trying numerous fixes, this finally seems to work:
The default logout functionality seems to not be properly clearing cookies via the FacebookMobile actionscript API. The solution in comment #33 here worked for me, reproduced here. Make sure to sub in your own APP_ID:
function logout(e:MouseEvent):void {
FacebookMobile.logout(onLogout, "https://m.facebook.com/dialog/permissions.request?app_id=APP_ID&display=touch&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&type=user_agent&perms=publish_stream&fbconnect=1");
}
function onLogout(result:Object):void
{
trace("Perfect Log Out!")
}
Have had this Android Facebook clean logout problem the whole day, manage to solve it. Hope it helps. Here is my FB mobile handlelogin code to ensure all fb cookies and sessions are being removed and user will need to relogin.
Sometimes FB server is very slow. Its best to put a timer before you call handleLoginClick() again
function handleLoginClick():void
{
trace("connecting to facebook");
if (FacebookMobile.getSession() == null)
{
FacebookMobile.init(APP_ID, onHandleInit, null);
FacebookMobile.manageSession = false
}
else
{
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, 1, 1);
webView.stage = this.stage;
webView.loadURL("https://m.facebook.com/logout.php?confirm=1&next=http://www.facebook.com&access_token=" + FacebookMobile.getSession().accessToken);
webView.addEventListener(Event.COMPLETE,webviewhandleLoad);
function webviewhandleLoad(e:Event)
{
FacebookMobile.logout(null, "http://apps.facebook.com/<appName>/");
FacebookMobile.logout(null, "http://www.facebook.com");
webView.dispose()
webView = null
setTimeout(handleLoginClick,3000)
}
}
}
look at the solution of this problem. Maby someone it helps:
var stage_ref:Stage = PlatformUtil.originalStage(); //my custom class to get stage
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, stage_ref.width, stage_ref.height);
FacebookMobile.login(loginCallback, stage_ref, appPermissions, webView);
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=381
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=382
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=383