X

Menu

Integrating Facebook login, getting Profile pic and name in Unity

FOR FACEBOOK LOGIN

STEP 1; Integrate Facebook plugin in Unity. (If you don’t know how to do it, go here for the tutorial

http://www.sagestudios.in/integrating-facebook-sdk-in-unity-for-android/)

STEP 2: Create an empty GameObject. Name it Fbholder.

STEP 3: Create a button. Name it Fblogin.

Drag and drop  the canvas inside the empty gameobject Fbholder. 

Screenshot (6)

STEP 4: Create a new C# script.Name it Fbholderscript  and attach it to Fbholder. Write the following codes on the script

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
public class Fbholderscript : MonoBehaviour {
List<string> perms=new List<string>(){“public_profile”,”email”,”user_friends”};
void Awake ()
{
if (!FB.IsInitialized) {
FB.Init(InitCallback, OnHideUnity);         // Initialize the Facebook SDK
} else {
FB.ActivateApp();          // Already initialized, signal an app activation App Event
}
}

private void InitCallback ()
{
if (FB.IsInitialized) {
FB.ActivateApp();                    // Signal an app activation App Event
} else {
Debug.Log(“Failed to Initialize the Facebook SDK”);        // Continue with Facebook SDK
}
}

private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
Time.timeScale = 0;                         // Pause the game – we will need to hide
} else {
Time.timeScale = 1;                        // Resume the game – we’re getting focus again
}
}
public void OnLogin(){
FB.LogInWithReadPermissions(perms, AuthCallback);
}
private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken; // AccessToken class will have session details
Debug.Log(aToken.UserId); // Print current access token’s User ID
foreach (string perm in aToken.Permissions) {
Debug.Log(perm); // Print current access token’s granted permissions
}
} else {
Debug.Log(“User cancelled login”);
}
}
}

STEP 5: Attach the OnLogin() function of the Fbholderscript to the button Fblogin.

 

If you followed the steps correctly you should have a functioning app that can login to your facebook

STEP 6:  Create an UI Image object and a UI text object. Name it profilepic and name respectively.

STEP 7: Update the code of Fbholderscript to the following

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
using UnityEngine.UI;
public class Fbholderscript : MonoBehaviour {

public Image profilepicture;
public Text nametext;
List<string> perms=new List<string>(){“public_profile”,”email”,”user_friends”};
void Awake ()
{
if (!FB.IsInitialized) {
FB.Init(InitCallback, OnHideUnity); // Initialize the Facebook SDK
} else {
FB.ActivateApp(); // Already initialized, signal an app activation App Event
}
}

private void InitCallback ()
{
if (FB.IsInitialized) {
FB.ActivateApp(); // Signal an app activation App Event
} else {
Debug.Log(“Failed to Initialize the Facebook SDK”);// Continue with Facebook SDK
}
}

private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
Time.timeScale = 0; // Pause the game – we will need to hide
} else {
Time.timeScale = 1; // Resume the game – we’re getting focus again
}
}
public void OnLogin(){
FB.LogInWithReadPermissions(perms, AuthCallback);
}
private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
FB.API (“/me?fields=name”, HttpMethod.GET, DispNAme); //getting the username
FB.API (“me/picture?type=square&height=150&width=150″, HttpMethod.GET, Getpicture);   //getting the profile picture

var aToken = Facebook.Unity.AccessToken.CurrentAccessToken; // AccessToken class will have session details
Debug.Log(aToken.UserId); // Print current access token’s User ID
foreach (string perm in aToken.Permissions) {
Debug.Log(perm); // Print current access token’s granted permissions
}
} else {
Debug.Log(“User cancelled login”);
}
}
void DispNAme(IResult result){
if (result.Error != null) {
nametext.text =”error “;
}
else{
nametext.text =” ” +result.ResultDictionary["name"];
}

}
private void Getpicture(IGraphResult result){
if (result.Error == null && result.Texture != null) {
profilepicture.sprite = Sprite.Create(result.Texture, new Rect (0, 0,150, 150), new Vector2 ());
}
}
}

STEP 7: Finally assign the UI object profilepic and UI text object name to Fbholderscripts’ profilepicture and nametext respectively.

 

 

If you did everything correct you should see your name and  profile picture once you play your project.

Sample:

Screenshot (7)

Integrating Facebook SDK in Unity for Android

STEP 1: Go to https://developers.facebook.com/docs/unity/  and download the Facebook SDK for Unity.

STEP 2: Once downloaded unzip the file. And go to the folder named FacebookSDK. From there Drag and Drop the Facebook plugin in your unity project’s asset folder. A window “import unity settings” will pop up. Just click import.

STEP 3: On the top left a new “Facebook” plugin will have popped up. Click on that and then click on edit settings

editsettings

STEP 4: Now open your browser and go to https://developers.facebook.com .   Login to your facebook account. Click on the Create App button on the top right corner of the page. Fill in the details and click Create App ID and verify captcha. Once done, Click on My apps and click on your app, it will lead you to the dashboard. Copy your App ID.

 

 

AppID

STEP 5: Now go back to Unity and paste the App ID on the APP ID slot in the Edit settings

 

 

 

AppIDpaste

STEP 6: Now copy the package name, class name and Debug android key hash from Android Build Facebook settings

class,keyhash

 

and paste them respectively in your app’s basic settings in developers.facebook.com

class,keyhashpaste

If you did everything correctly , then your app should be integrated to Facebook.

For no man can alter or change the word of God as it was

Mrs. Toll said that Revlon was interested in her invention at one point, but that after a change in management the company lost enthusiasm. ”The trick is for us to get it engineered so that the mascara wipes off the brush as it comes out of the case,” her husband, Albert, said.

micro neddling But the allegations that he had lured Jones to his hotel room, lowered his pants, and then tried to coerce her into performing oral sex dealt only with Bill’s behavior before he stepped onto the national stage. Besides, while Hillary knew that her husband had been unfaithful in Arkansas with a lounge singer named Gennifer Flowers, when it came to Paula Jones she believed Bill’s denials. Paula was merely a pawn of her husband’s political enemies, Hillary firmly believed. micro neddling

skin roller Soldier was gagging, drowning in blood without a mouth or nose. A medic performed an emergency tracheotomy. The soldier died anyway.. In the summer of 2010, while the world breathlessly awaited LeBronJames’ infamous decision, Durant announced, through a simple tweet,that he had signed an extension with the Thunder (it was a five year,$85 million deal). This quiet, unassuming move cast Durant as theanti LeBron. While James was looking to leave Cleveland for a glitzierdestination, and staging an obnoxious television special to stick itto his hometown fans, Durant showed loyalty by staying in Oklahoma,and humility by declaring intentions through a low key tweet.. skin roller

facial roller The mobile phone came about because businesses and consumers needed something that would make communication easier. Research in the area was hampered because the Federal Communications Commission (FCC) placed restrictions on the allocation of frequencies. That was when AT introduced the ideas of a cellular system. facial roller

microneedle roller The interior of one’s mouth cavity feels larger when explored by the tongue than when looked at. The crater of a, newly extracted tooth, and the movements of a loose tooth in its socket, feel quite monstrous. A midge buzzing against the drum of the ear will often seem as big as a butterfly. microneedle roller

needle derma roller 9Load the sewing machine with needle and thread appropriate to your fabric. Stitch each loop along the top hem of your wall hanging to reduce the number of visible lines in your wall hanging. Be sure to lock your seams by hitting the “reverse” button on your sewing machine at each edge of the loop.. needle derma roller

Madame, he said. Later I found out that he was being punished for adultery. After the pari vente he had slept with a married woman.. Dilute in a carrier oil before use.Sandalwood Essential OilSandalwood is useful in the treatment of acne, mature, dry skin and scars. It is another expensive oil, but is often worth the cost. It is a base note essential oil.

Enough about that what I really wanted say to you is Merry Christmas. My wish is that you are celebrating with family and friends and having a wonderful time. I love this time of the year. This interrelationship of organisms is one focus of the book. How humans are like and unlike other animals is another recurring theme. Evolution is http://www.microskinroller.com/ derma roller, of course, key to these ideas; so much of the text is devoted to heredity, genetics and natural selection.

needle skin care Dear Anderson Copper! It is written in the bible that men would be lovers of men; women Lovers of women and mankind would be lovers of self. Whatever God has revealed is living and true. For no man can alter or change the word of God as it was revealed. needle skin care

Les consommateurs aguerris s’tonneront : Qubec n’avait il pas interdit les dates d’expiration sur les cartes cadeaux et les cartes prpayes? Oui, c’est vrai. Depuis 2010, fini, les dates d’expiration sur les cartes prpayes, fini, les frais cachs qui grugeaient en douce le solde des clients. Avec la rforme de la Loi sur la protection du consommateur, les commerants sont mme obligs de rendre la monnaie lorsque le solde de la carte est infrieur 5$..

derma roller Adults should set an example for children and wear a helmet when cycling, the researchers suggested in a clinic news release. Get kids used to wearing a helmet at a young age, such as when they start riding a tricycle. As long as it fits properly, let children choose their helmet derma roller.

Niacin helps keep your skin and nerves healthy and functioning

benefits of green tea for diabetes patients

yeti tumbler The gene knockout animal is a potent tool to analyze the role of cytokines in various diseases. The gene knockout animal, however, is not suitable for this purpose, because VEGF disrupted animals usually die during the embryonic period.12 At the same time, VEGF gene transgenic mice showed the importance of VEGF in retinochoroidal angiogenesis, but SRN in their animals was also formed during embryogenesis and so does not reflect the SRN forming process in adults.13 Since SRN, especially in age related macular degeneration, is a disease of adulthood, new evidence is thus necessary. Recently, VEGF neutralization by a specific antibody was reported to inhibit tumor angiogenesis in species,14 therefore, VEGF neutralization might also inhibit SRN formation in age related macular degeneration. yeti tumbler

Of the Best of Bridge recipes are geared toward entertaining but casual entertaining that not intimidating, Van Rosendaal pointed out. The kind of home cooking that makes you just want to be in their kitchen, sitting at the table, and having a glass of wine while they cook. Of the Best of Bridge tried and true recipes that has stood the test of time, Hamburger Soup, has been adapted for the slow cooker and appears in the new cookbook..

yeti tumbler colors Even as I write this, I still cannot begin to fathom how the de facto raciest metropolis on the planet gravitated (or degenerated) from woolen jackets and shawls which is what the Euro posturing elite would wear in the height of summer to ball hangers and nipple badges. Across from the Meridian Hotel a group of high school types stands under a four head shower station, provided for a small fee by a one man pump and bucket operation. One of the boys wears a permanently cheeky grin, as if he were pulling one over on the whole world. yeti tumbler colors

yeti tumbler sale He both follows and attends domestic cricket (several times Tyson refers to the Ryobi Cup and Sheffield Shield, but not the Big Bash) http://www.cheapyetitumbler.com/ cheap yeti tumbler, is in awe of its quality, and drawn to the border drawn rivalry between combatants. “We pop into the shield. You can almost hear the mozzies buzzing around, but it’s great cricket. yeti tumbler sale

cheap yeti cups Slice all but 3 or 4 strawberries. Gently mix sliced berries in bowl with 1/4 cup sugar; let sit for 15 minutes. Cover the bottom of a large trifle dish (clear, stemmed bowl) with a layer of the cake squares. Salt 3/4 c. Firmly packed brown sugar 1 c. White chocolate chips 2/3 c. cheap yeti cups

yeti cup The hours had been a mosh pit of sweating bodies swaying to the band. All for St. Patrick, a holy man from Wales who banished snakes and Celtic paganism.. This city’s luxury shopping scene is well publicised but leave the slick (although mercifully air conditioned) malls for a snoop around one of Hong Kong’s many local markets. There are the usual suspects like Temple Street Market, where you can buy everything from imitation paintings and I Love Hong Kong t shirts to fake branded underwear and vibrators and the ones that are more interesting. The street markets in fast gentrifying, boho Sham Shui Po on the fringes of Kowloon sell everything from multipacks of TV remotes to gelatinous bowls of snake soup; while 160 year old Graham Street wet market, the city’s oldest, sells super fresh fish and vegetables under trademark swinging red lamps. yeti cup

A large adherent clot was seen in the mid sigmoid. The clot was flushed away and a small neck diverticulum was noted beneath. A tiny erosion was noted at the neck of the diverticulum, but no visible vessel could be seen. Food and Beverages Most companies throw away a lot of paper, cans and cups in the bin every single day since employees indulge in lots of coffee and food during their work hours. This leads to a huge amount of waste and rarely is any of it recyclable. Businesses should promote home cooking or baking days where you can get employees to showcase their creativity and have lesser waste.

cheap yeti tumbler Two tablespoons of peanut butter also provide 0.6 milligrams of iron and 4.3 milligrams of the 14 to 16 milligrams of niacin you need each day. Niacin helps keep your skin and nerves healthy and functioning properly. You also get 2.88 of the 15 milligrams of vitamin E you need on a daily basis. cheap yeti tumbler

“I don make it any other time unless we going on a picnic,” she says. “I decided to bake the chicken wings at a very low heat to get them nice and crispy and they wonderful cold. It was my husband idea to squirt lemon on them. But returning to a casserole classic doesn’t necessarily mean reaching for the can of cream of mushroom soup that’s been in your pantry since the Eisenhower administration. There’s no excuse not to saute your own mushrooms or celery, stir in flour and fat, and then add milk to make your own creamy sauce. Trust me.