Facebook登录页面不显示我的分数只发生在管理员身上

时间:2015-07-06 22:10:08

标签: facebook facebook-graph-api

在我登录Facebook和所有内容之后,它运行正常但是当我尝试显示我朋友的分数时它不会带来分数,分数总是为零,除了管理员帐户是我的,它显示我的实际分数,这里是Facebook的脚本以及我的得分经理的任何建议吗?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ScoreManager : MonoBehaviour {

    public static int score;

    Text scoretext;

    void Start () 
    {
        scoretext = GetComponent<Text> () ;
        //score = 0;

        score = PlayerPrefs.GetInt("CurrentPlayerScore");
    }

    void Update () 
    {
        if (score <0)
            score = 0;
        scoretext.text = "" + score;
    }

    public static void AddPoints (int pointsToAdd)
    {
        score +=pointsToAdd;
        PlayerPrefs.SetInt ("CurrentPlayerScore", score);
    }

    public static void Rest()
    {
        score = 0;
        PlayerPrefs.SetInt("CurrentPlayerScore", score);
    }
}

这是Facebook的一个

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

public class FBholder : MonoBehaviour 
{
    public GameObject UIFBIsLoggedIn;
    public GameObject UIFBIsNotLoggedIn;
    public GameObject UIFBAvatar;
    public GameObject UIFUserName;

    private List<object> scoresList = null;

    public GameObject ScoreEntryPanel;
    public GameObject ScoreScrollList;

    public static int score;

    private Dictionary<string, string> profile = null;

    void Awake()
    {
        FB.Init (SetInit, OnHideUnity);
    }

    void Start()
    {
        score = PlayerPrefs.GetInt("CurrentPlayerScore");
    }


    private void SetInit()
    {
        Debug.Log ("FB Init done.");

        if(FB.IsLoggedIn)
        {
            DealWithFBMenus(true);
            Debug.Log ("FB Logged In");
        }
        else
        {
            DealWithFBMenus(false);
        }

    }

    private void OnHideUnity(bool isGameShown)
    {

        if(!isGameShown)
        {
            Time.timeScale =0;
        }
        else
        {
            Time.timeScale =1;
        }


    }

    public void FBlogin()
    {
        FB.Login ("email,publish_actions", AuthCallback);
    }

    void AuthCallback (FBResult result)
    {
        if (FB.IsLoggedIn)
        {
            Debug.Log ("FB Login worked!");
            DealWithFBMenus(true);
        }
        else
        {
            Debug.Log ("Fb Login fail");
            DealWithFBMenus(false);
        }
    }

    void DealWithFBMenus (bool isLoggedIn)
    {
        if(isLoggedIn)
        {
            UIFBIsLoggedIn.SetActive(true);
            UIFBIsNotLoggedIn.SetActive(false);

            FB.API (Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
            FB.API ("/me?field=id,first_name",Facebook.HttpMethod.GET, DealWiththeUserName);
        }
        else
        {
            UIFBIsLoggedIn.SetActive(false);
            UIFBIsNotLoggedIn.SetActive(true);
        }
    }

    void DealWithProfilePicture(FBResult result)
    {
        if (result.Error != null)
        {
            Debug.Log ("Problem with getting profile picture");

            FB.API (Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
            return;
        }

        Image UserAvatar = UIFBAvatar.GetComponent<Image>();
        UserAvatar.sprite = Sprite.Create (result.Texture, new Rect (0,0,128, 128), new Vector2 (0,0));
    }

    void DealWiththeUserName (FBResult result)
    {
        if (result.Error != null)
        {
            Debug.Log ("Problem with getting user name");

            FB.API ("/me?field=id,first_name",Facebook.HttpMethod.GET, DealWiththeUserName);
            return;
        }

        profile = Util.DeserializeJSONProfile(result.Text);

        Text UserMsg = UIFUserName.GetComponent<Text>();

        UserMsg.text = "Hello, " + profile["first_name"];
    }

    public void ShareWithFriends()
    {
        FB.Feed (
            linkCaption: "I'm Playing this awesome game check it out!",
            picture: "http://stormyx.com/MyGameIcon.png",
            linkName: "Come join me in this game now!",
            link: "http://app.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")


            );
    }

    public void InviteFriends()
    {
        FB.AppRequest
            (
                message: "This game is Fantastic!, join me now!",
                title: "Invite your friends to join you"
                );
    }

    public void FriendsScore()
    {
        FB.API ("/app/scores?fields=score,user.limit(30)", Facebook.HttpMethod.GET,ScoresCallback);
    }

    private void ScoresCallback (FBResult result)
    {
        Debug.Log ("Scores callback: " + result.Text);

        scoresList = Util.DeserializeScores (result.Text);

        foreach(Transform child in ScoreScrollList.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        foreach(object score in scoresList)
        {
            var entry = (Dictionary<string,object>) score;
            var user = (Dictionary<string,object>) entry ["user"];


            GameObject ScorePanel;
            ScorePanel = Instantiate (ScoreEntryPanel) as GameObject;
            ScorePanel.transform.parent = ScoreScrollList.transform;

            Transform ThisScoreName = ScorePanel.transform.Find ("FriendName");
            Transform ThisScoreScore = ScorePanel.transform.Find ("FriendScore");
            Text ScoreName = ThisScoreName.GetComponent<Text>();
            Text ScoreScore = ThisScoreScore.GetComponent<Text>();


            ScoreName.text = user["name"].ToString();
            ScoreScore.text = entry["score"].ToString();

            ScoreName.text = user["name"].ToString();
            ScoreScore.text = entry["score"].ToString();

            Transform TheUserAvatar = ScorePanel.transform.Find ("FriendAvatar");
            Image UserAvatar = TheUserAvatar.GetComponent<Image>();

            FB.API (Util.GetPictureURL(user["id"].ToString(), 128,128), Facebook.HttpMethod.GET,delegate(FBResult pictureResult) 
                    {
                if(pictureResult.Error != null)
                {
                    Debug.Log (pictureResult.Error);
                } 
                else
                {
                    UserAvatar.sprite = Sprite.Create (pictureResult.Texture, new Rect (0,0,128, 128), new Vector2 (0,0));
                }
            });


        }
    }

    public void MyScore()
    { 
        var scoreData = new Dictionary<string,string>();
        scoreData ["score"] = (score).ToString();
        FB.API ("/me/scores", Facebook.HttpMethod.POST, delegate(FBResult result)
                {
            Debug.Log ("Score submit result: " + result.Text);
        }, scoreData);
    }

    public void StartGame ()
    {
        PlayerPrefs.SetInt("CurrentPlayerScore",0);
        Application.LoadLevel (1);
    }

    public void Quit ()
    {
        Application.Quit ();
    }



}

0 个答案:

没有答案
相关问题