Unity Facebook Parse登录卡住了

时间:2015-04-16 04:36:31

标签: c# facebook facebook-unity-sdk

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Facebook.MiniJSON;
using Parse;
using System;
using System.Threading.Tasks;

public class FacebookLogin : MonoBehaviour 
{
    #region Variables
    // Inspector Assigned.
    public Text _Username;

    // Private.
    private static Dictionary<string, string> _Profile          = null;

    // Store searched friends data.
    #endregion

    #region Functions
    public void Awake()
    {
        FB.Init( SetInit, OnHideUnity );
        ParseClient.Initialize( "IdidPutThis", "AlsoThis" );
    }
    #endregion

    #region Setup
    void SetInit()
    {
        if( FB.IsLoggedIn )
            OnLoggedIn();
    }

    void OnHideUnity( bool shown )
    {
        if( shown )
            Time.timeScale = 1f;
        else
            Time.timeScale = 0f;
    }   
    #endregion

    #region Login
    void OnLoggedIn()
    {
        // Request player info and profile picture.
        FB.API( "/me?fields=id,first_name", Facebook.HttpMethod.GET, OnLoginCallback );
        LoadPictureAPI( Util.GetPictureURL( "me", 128, 128 ), MyPictureCallback );
    }

    void LoginCallback( FBResult result )
    {
        if( FB.IsLoggedIn )
            OnLoggedIn();
    }
    #endregion

    #region Callbacks
    void OnLoginCallback( FBResult result )
    {
        if( result.Error != null )
        {
            Debug.Log( "Trying again.." );
            FB.API( "/me?fields=id,first_name,invitable_friends.limit(100).fields(first_name,last_name,id,picture.width(128).height(128))", Facebook.HttpMethod.GET, OnLoginCallback );
            return;
        }
        else
            StartCoroutine( "ParseLogin" );

        // Get user profile, and invitable friends list.
        _Profile          = Util.DeserializeJSONProfile( result.Text );

        _Username.text = "Name: " + _Profile[ "first_name" ];
    }

    private void appRequestCallback( FBResult result )
    {
        if( result != null )
        {
            var responseObject = Json.Deserialize( result.Text ) as Dictionary<string, object>;
            object obj = 0;

            if( responseObject.TryGetValue( "cancelled", out obj ) )
                Util.Log("Request cancelled");
        }
    }


    void MyPictureCallback( Texture texture )
    {
        if( texture == null )
        {
            // Let's just try again
            LoadPictureAPI( Util.GetPictureURL( "me", 128, 128 ), MyPictureCallback );
            return;
        }

//      GlobalVars._ProfilePic = texture;
    }

    IEnumerator ParseLogin()
    {
        if( FB.IsLoggedIn )
        {
            Debug.Log( "SHIT" );
            var loginTask = ParseFacebookUtils.LogInAsync( FB.UserId, FB.AccessToken, DateTime.Now );

            while( !loginTask.IsCompleted )
            {
                Debug.Log( "Testing..." );
                yield return null;
            }

            if( loginTask.IsFaulted || loginTask.IsCanceled )
                Debug.Log( "PARSE ERROR" );
            else
                Debug.Log( "Parse login successful" );
        }
    }

    #endregion

    #region Click Functions.
    public void Login()
    {
        if( FB.IsInitialized )
            FB.Login( "public_profile,user_friends,email", LoginCallback );
    }
    #endregion

    #region Picture
    delegate void LoadPictureCallback( Texture texture );

    IEnumerator LoadPictureEnumerator( string url, LoadPictureCallback callback )    
    {
        WWW www = new WWW( url );
        yield return www;
        callback( www.texture );
    }

    void LoadPictureAPI( string url, LoadPictureCallback callback )
    {
        FB.API(url,Facebook.HttpMethod.GET,result =>
               {
            if (result.Error != null)
            {
                Util.LogError(result.Error);
                return;
            }

            var imageUrl = Util.DeserializePictureURLString(result.Text);

            StartCoroutine(LoadPictureEnumerator(imageUrl,callback));
        });
    }

    void LoadPictureURL (string url, LoadPictureCallback callback)
    {
        StartCoroutine(LoadPictureEnumerator(url,callback));

    }
    #endregion
}

Facebook登录,我显示用户名,它可以正常工作。然而,当登录Parse时它会被击中,它只是记录日志&#34;测试...&#34;在调试日志中。没有显示错误,它只是没有进行。

使用Unity 5.0.1p1,最新的Facebook SDK和Parse SDK。

由于

0 个答案:

没有答案
相关问题