我目前有2个问题
我使用统一 5.2.0 和 Facebook unity sdk 7.2 我的统一设置为 PC 构建(我将解释为什么刚才)
我一直在关注灰色区域的教程,并根据新 SDK 的需要对其进行调整。在我的统一编辑器中,我目前为我的个人资料图片、用户名、分享和邀请按钮以及 Facebook 登录按钮提供了一个位置。当我运行这个项目时,它完美地贯穿了一切。它获取个人资料图片和用户名并将它们放在需要的位置,共享和邀请按钮会在日志中发布它们正在工作的信息,这很好。我的第一个问题是:当我将编辑器放入网络播放器构建时,尝试登录时总是出现此错误。有关修复此部分的任何建议?
ArgumentException:无法覆盖标头:用户代理 UnityEngine.WWW.CheckSecurityOnHeaders(System.String[] 标头)(在 C:/buildslave/unity/build/Runtime/Export/WWW.cs:71)UnityEngine.WWW..ctor( System.String url,System.Byte[] postData,System.Collections.Generic.Dictionary`2 标头)(在 C:/buildslave/unity/build/artifacts/generated/common/runtime/UtilsBindings.gen.cs:125) Facebook.Unity.AsyncRequestString+c__Iterator1.MoveNext () (在 Assets/Facebook/Scripts/Utils/AsyncRequestString.cs:100)
我的第二个问题是:我构建了我的项目(网络播放器构建)并将其上传到我的托管服务器,然后当我跳上 Firefox 或 Internet Explorer 并在 Facebook 画布上访问我的应用程序时,它会加载,但是个人资料图片和用户名不出现。然而,共享和邀请工作。它只有不通过的图片和名称。
我将把我所有的代码都放进去,这样你就可以准确地看到我做了什么。抱歉,我对编码很陌生,所以它可能看起来很糟糕。
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using UnityEngine.UI;
using System;
public class FBholder : MonoBehaviour
{
public GameObject UIFBIsLoggedIn;
public GameObject UIFBIsNotLoggedIn;
public GameObject UIFBAvatar;
public GameObject UIFBUserName;
public GameObject ErrorText;
public Text errorText;
private Dictionary<string, string> profile = null;
void Awake()
{
FB.Init (SetInit, OnHideUnity);
}
private void SetInit()
{
errorText = ErrorText.GetComponent<Text>();
Debug.Log ("FB Init done.");
//LOG: Error Text
errorText.text = "FB Init done.";
Debug.LogWarning("LOG "+ errorText.text);
if (FB.IsLoggedIn)
{
DealWithFBMenus(true);
Debug.Log ("FB Logged In.");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "FB Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}else{
DealWithFBMenus(false);
FindTheStupidErrorLog();
errorText.text = "FB Not Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}
}
private void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}else{
Time.timeScale = 1;
}
}
public void FBlogin ()
{
var perms = new List<string>(){"public_profile", "email",};
FB.LogInWithReadPermissions(perms, AuthCallback);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "FB Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
DealWithFBMenus(true);
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log(aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log(perm);
}
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "AuthCallback if";
Debug.LogWarning("LOG "+ errorText.text);
} else {
DealWithFBMenus(false);
Debug.Log("User cancelled login");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "AuthCallback else";
Debug.LogWarning("LOG "+ errorText.text);
}
}
void DealWithFBMenus(bool isLoggedIn)
{
if(isLoggedIn)
{
UIFBIsLoggedIn.SetActive (true);
UIFBIsNotLoggedIn.SetActive (false);
FB.API (Util.GetPictureURL("me", 128, 128), HttpMethod.GET, DealWithProfilePicture);
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "running deal with menu If";
Debug.LogWarning("LOG "+ errorText.text);
}else{
UIFBIsLoggedIn.SetActive (false);
UIFBIsNotLoggedIn.SetActive (true);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "running deal with menu else";
Debug.LogWarning("LOG "+ errorText.text);
}
}
void DealWithProfilePicture (IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problem getting Pic");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Profile Pic Error";
Debug.LogWarning("LOG "+ errorText.text);
FB.API (Util.GetPictureURL("me", 128, 128), 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));
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Profile Pic loaded";
Debug.LogWarning("LOG "+ errorText.text);
}
void DealWithUserName (IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problem getting Pic");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "UserName didnt loaded";
Debug.LogWarning("LOG "+ errorText.text);
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.Text);
Text UserMsg = UIFBUserName.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "UserName loaded";
Debug.LogWarning("LOG "+ errorText.text);
}
public void ShareWithFriends()
{
if (!FB.IsLoggedIn)
{
FBlogin();
Debug.Log ("not logged in to share");
}else {
Uri contentUri = new Uri("http://apps.facebook.com/" +FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? AccessToken.CurrentAccessToken.UserId : "guest"));
FB.ShareLink(
contentURL: contentUri,
contentTitle: "Me Testing the FB SDK",
contentDescription: "I wonder where this shows?",
photoURL: new Uri("https://dragondigital.co.za/fb_7.1_test/mascotOne.png"),
callback: ShareCallback
);
}
}
private void ShareCallback (IShareResult result)
{
if (result.Cancelled || !String.IsNullOrEmpty(result.Error)) {
Debug.Log("ShareLink Error: "+result.Error);
} else if (!String.IsNullOrEmpty(result.PostId)) {
// Print post identifier of the shared content
Debug.Log(result.PostId);
} else {
// Share succeeded without postID
Debug.Log("ShareLink success!");
}
}
public void InviteFriends()
{
FB.AppRequest(
message: "This is the Invite Message",
title: "This is the Invite Title."
);
print ("Invite prob worked");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Invite prob worked";
}
public void FindTheStupidErrorLog()
{
if(errorText == null)
{
errorText = ErrorText.GetComponent<Text>();
}
}
}
是的,我知道有很多冗余错误日志记录,但稍后会删除:)
你们可以提供的任何帮助将不胜感激:)