Grey Zoned

Facebook SDK 7.4.0 in Unity 5.3 Tutorial – Singletons, Inviting & Sharing

Lets learn how to invite and share our game.

Watch the full video for an in-depth explanation of how to put this all together. However if you just want a quick cheat sheet of how to do shares and invites then look no further than the following code:

Sharing

 


public void Share()
	{
		FB.FeedShare (
			string.Empty,
			new Uri("http://linktoga.me"),
			"Hello this is the title",
			"This is the caption",
			"Check out this game",
			new Uri("https://i.ytimg.com/vi/NtgtMQwr3Ko/maxresdefault.jpg"),
			string.Empty,
			ShareCallback
		);
	}

	void ShareCallback(IResult result)
	{
		if (result.Cancelled) {
			Debug.Log ("Share Cancelled");
		} else if (!string.IsNullOrEmpty (result.Error)) {
			Debug.Log ("Error on share!");
		} else if (!string.IsNullOrEmpty (result.RawResult)) {
			Debug.Log ("Success on share");
		}
	}

Inviting


public void Invite()
	{
		FB.Mobile.AppInvite (
			new Uri("http://linktoga.me"),
			new Uri("https://i.ytimg.com/vi/NtgtMQwr3Ko/maxresdefault.jpg"),
			InviteCallback
		);
	}

	void InviteCallback(IResult result)
	{
		if (result.Cancelled) {
			Debug.Log ("Invite Cancelled");
		} else if (!string.IsNullOrEmpty (result.Error)) {
			Debug.Log ("Error on invite!");
		} else if (!string.IsNullOrEmpty (result.RawResult)) {
			Debug.Log ("Success on Invite");
		}
	}

Check the resources sidebar where you can download the full source code of this tutorial.

If you have any issues, please ask your questions in the support thread from the forum below this article or go to the full thread on the forums here

Happy Coding!
Glenn

Glenn Mason

Tutorial by Glenn Mason

I've been interested in Game Development since I was about 11 years old when I started by making levels for Duke Nukem 3D, later moving on to creating Half-Life and Counter-Strike maps. Once I got into coding I went down the route of learning to make websites and web applications. Now I'm a professional Web Developer, running my own freelance business. However, my heart is still in Game Development. I started using Unity late in 2013. Since then I've released two Apps on the App stores that use Unity.

Tutorial Discussion

Home Forums Facebook SDK 7.4.0 in Unity 5.3 Tutorial – Singletons, Inviting & Sharing

Tagged: 

This topic contains 36 replies, has 28 voices, and was last updated by  Jeniffer P 4 months, 3 weeks ago.

Viewing 7 posts - 31 through 37 (of 37 total)
  • Author
    Posts
  • #763

    smitsc
    Participant

    I am investigating turn based multiplayer game also, have you settled no back-end service yet? GameSparks, App42 or PlayFab, they’re pricing doesn’t seam to translate well to turn-based games?? If you’re developing with Unity I don’t think cross platform is an issue. I’ve had no problems communicateing between PC, Unity editor and Android, haven’t launched on iPhone/testflight yet. Scott@VirtualBS.com

    #765

    Donato Flores
    Participant

    Hi, I really need to share from Unity to Facebook, in a Facebook page that I manage, not to my profile, could yo help me?

    #774

    Krisna Nugroho
    Participant

    Hello, I just followed your video tutorial and it works fine up until 30:10 mins. After moving some methods from FacebookManager.cs to FBScript.cs, when I play the Unity and input my access token the unity editor freeze up and won’t respond, do you know what’s wrong with it ?

    #784

    Amir Ferdosinezhad
    Participant

    Thank you for your awesome videos.

    Everything seems to work just fine on unity Editor, however, when I build it on iOS and test it on my phone. as soon as I hit the logging button, it crashes.
    Xcode returns the following error:

    // iOS terminates open sockets when an application enters background mode.
    // The next write to any of such socket causes SIGPIPE signal being raised,
    // even if the request has been done from scripting side. This disables the
    // signal and allows Mono to throw a proper C# exception.
    std::signal(SIGPIPE, SIG_IGN);

    UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String:AppControllerClassName]);

    So I’m guessing the problem occurs when it tries to launch facebook for authentication and puts my game in the background but I don’t know how to fix it. please help me.
    PS: this also makes my phone slow as a snail and nothing works except for Siri, which is weird.
    Thank you.

    #787

    Seong-Jik KIM
    Participant

    Hi, Glenn.
    Really appreciate your tutorial.
    I am using Galaxy S6 (Android 6.0.1), Unity 5.5 and Facebook SDK for Unity 7.9, but my current apk build doesn’t work well with it when I open the app on my Smartphone.
    I am sharing my google document including screenshots both of Unity 5.5 editor and Galaxy S6.
    https://docs.google.com/document/d/1_I99Pa479CwQwzQvRTrVGUwYoyH6rZ2RT3yP0ClBxaY/edit?usp=sharing

    How can I resolve my current problem?

    #791

    Alejo Gómez
    Participant

    i have a problem, my app doesnt’ share correctly on facebook, i want share new record with this code:

    public void Share(int record)
    {
    string record_string = “Nuevo Record: ” + record.ToString ();

    FB.FeedShare (
    string.Empty,
    new Uri(“https://play.google.com/store/apps/details?id=com.TrialisStudios.Casita_Fantasma&hl=es”),
    “Casita Fantasma”,
    “He superado mi record”,
    record_string,
    new Uri(“https://www.dropbox.com/s/e8y9fjb5c1mix81/logo.png”),
    string.Empty,
    ShareCallback
    );

    }
    If anyone could help me please

    • This reply was modified 5 months, 2 weeks ago by  Alejo Gómez.
    #797

    Jeniffer P
    Participant

    After implementing “sharing” function, I supposed to see the picture: https://i.ytimg.com/vi/NtgtMQwr3Ko/maxresdefault.jpg at my own facebook website, right?

    But I cannot see it, which means the shared function does not really work.
    Yeah, I got the exactly same windows you have with 3 different buttons, but even though I click “share success” and got the “Success on share” debug message, I still cannot see the shared picturelink at my facebook page.

    Am I missing something important to know? Thanks

Viewing 7 posts - 31 through 37 (of 37 total)

You must be logged in to reply to this topic.