- Home /
How to share high score(string)/game result data on facebook ...please any one help me ....:(.
Friends i really need your help .... its been i am trying to just show my game result on facebook :(...what i want, at the end of my game i get a result in string like high score... i just want to show that on face book as to post on your own facebook wall ... i have installed facebook sdk 5.1, made an app id on developers.facebook page .. put that name and the app id in the facebook settings in the unity3d editor .. but i am not figuring it out how we will share the result ... i tried to get help from the friendssmash but its complicated .. they are not showing properly ... is there any other scripts that we need to write ..there will be ... please help me .. i am stuck at the end of my game .. :"(
Answer by Omer.Hussain · Jun 03, 2014 at 07:16 AM
Actually in the fb.Init() i removed the OnHideUnity and it works ... in OnHideUnity game get pause before sharing .... strange ... Thanks for all of you for help ... :) ..
Answer by PouletFrit · May 28, 2014 at 02:19 PM
With the Facebook SDK for Unity you will need to call the FB.Feed function and give it the good parameters. Just add your score in the linkDescription or in the linkName.
Take a look at this link: FB.Feed Reference
Exemple:
FB.Feed(
link: "https://example.com/myapp/?storyID=thelarch",
linkName: "The Larch",
linkCaption: "I thought up a witty tagline about larches",
linkDescription: "There are a lot of larch trees around here, aren't there?",
picture: "https://example.com/myapp/assets/1/larch.jpg",
callback: LogCallback
);
void LogCallback(FBResult response) {
Debug.Log(response.Text);
}
Thanks for your response , i know this is again dum question ... actually i am new to program$$anonymous$$g ... and just learn javascript yet ..... i wrote this ... i think i wrote it not correctly ..
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.$$anonymous$$iniJSON;
using System;
public class ButtonFbShare : $$anonymous$$onoBehaviour {
string appid;
void Awake(){
FB.Init(SetInit, OnHideUnity);
}
private void SetInit() {
enabled = true;
// "enabled" is a magic global; this lets us wait for FB before we start rendering
}
private void OnHideUnity(bool isGameShown) {
if (!isGameShown) {
// pause the game - we will need to hide
Time.timeScale = 0;
} else {
// start the game back up - we're getting focus again
Time.timeScale = 1;
}
}
void On$$anonymous$$ouseDown(){
FB.Feed (
link: "https://developers.facebook.com/apps/"+appid,
linkName: "Love$$anonymous$$eLove$$anonymous$$eNot",
linkCaption: "Here is the Result of my Love$$anonymous$$eLove$$anonymous$$eNot Result",
linkDescription: "$$anonymous$$y Love$$anonymous$$eLove$$anonymous$$eNot Result is Perfect"
// picture: "https://example.com/myapp/assets/1/larch.jpg",
// callback: LogCallback
);
}
}
shows me this error
NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:264) UnityEngine.GUILayoutUtility.GetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:257) Facebook.FbSkinnedDialog.TwoButtonBar (System.String label, System.String cancelLabel) Facebook.FeedDialog.UpdateDialog (Int32 windowID) Facebook.FbSkinnedDialog.GeneralUpdateDialog (Int32 windowId) UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUI.cs:1395)
To fix the optional parameter error move line 17 to the top of the parameters list. Or give it a default value.
I think ur getting this error because u are running it in the editor.
Have u tryed to test it directly on facebook?
Also there should be somewhere in ur script that you use FB.Login, otherwise i doubt that you will be able to use FB.Feed
private void SetInit() {
FB.Login("publish_actions", OnLoggedIn);
}
void OnLoggedIn(FBResult result) {
if (FB.IsLoggedIn) {
Debug.Log("Logged in successfully");
}
}
now i have updated the code just for test .... run on my android device ... when i click the login button it show facebook page to login... after log in its ask me that this app wants your friends ,pics etc etc etc type... i click ok .. after that it doesn't show the next activity in which we select our friend or post on our on wall ....i think the error could be because in the face book setting it doesn't show hash key .. is this happening because of hash key ... ?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.$$anonymous$$iniJSON;
using System;
public class ButtonFbShare : $$anonymous$$onoBehaviour {
void Start()
{
FB.Init(OnInitComplete, OnHideUnity);
}
void OnInitComplete()
{
Debug.Log("FB Initialized");
}
void OnHideUnity(bool isGameShown)
{
Debug.Log("OnHideUnity");
if (!isGameShown)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
void Update()
{
}
void OnGUI()
{
if (!FB.IsLoggedIn)
{
if (GUI.Button(new Rect(10, 10, 100, 30), "Login"))
FBLogin();
}
else
{
if (GUI.Button(new Rect(10, 50, 100, 30), "Brag"))
{
Brag();
}
}
}
void Brag()
{
FB.Feed(
linkCaption: "This is testing the testapp FEED",
picture: "http://myapp.com/myapplogo.jpg",
linkName: "Foo Link",
link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
);
}
void FBLogin()
{
FB.Login("email, publish_actions", OnLoggedIn);
}
void OnLoggedIn(FBResult result)
{
if (FB.IsLoggedIn)
Debug.Log("Logged in successfully");
}
}