如何使用Facebook Unity SDK 7.0.3 Beta获取我的个人资料图片?

时间:2015-09-11 11:13:20

标签: facebook-unity-sdk

我正在使用Facebook Unity SDK 7.0.3 Beta,我正在尝试加载我的个人资料图片:

// Connection uses its own timeout value hardcoded in ExtJS - we remove it so that Ext.data.Connection will then
// fallback to using Ext.Ajax.timeout, thus giving a single place for setting the timeout
// Bonus: you can change this at runtime
Ext.define('Monitoring.overrides.Connection', {
  override: 'Ext.data.Connection',
  constructor: function() {
    delete this.timeout;
    this.callParent(arguments);
  }
});
Ext.define('Monitoring.overrides.ProxyServer', {
  override: 'Ext.data.proxy.Server',
  constructor: function() {
    delete this.timeout;
    this.callParent(arguments);
  }
});

MyPictureCallback定义:

FB.API("/me/picture", HttpMethod.GET, MyPictureCallback);

在以前的版本中,使用FBResult类型而不是IGraphResult,它具有Texture属性。 IGraphResult没有获取纹理的属性。

那么如何才能检索我的个人资料图片?

由于

3 个答案:

答案 0 :(得分:0)

您可以使用此方法生成图像URL,然后使用WWW类下载个人资料图片本身

public string GetFBPictureURL (string facebookID, int? width = null, int? height = null, string type = null)
        {
                string url = string.Format ("/{0}/picture", facebookID);
                string query = width != null ? "&width=" + width.ToString () : "";
                query += height != null ? "&height=" + height.ToString () : "";
                query += type != null ? "&type=" + type : "";
                query += "&redirect=false";
                if (query != "")
                        url += ("?g" + query);
                return url;
        }

答案 1 :(得分:0)

您必须执行以下操作:

  1. 添加'this.Texture = result.texture;'到GraphResult构造函数。
  2. 添加'public Texture2D Texture {get;私人集; }'到GraphResult.cs
  3. 添加'Texture2D Texture {get; ''到IGraphResult.cs,以及'使用UnityEngine;'
  4. 随着这两个条款的变化,现在你的IGraphResult将包含你之前拥有的纹理,你可以继续工作,就像什么都没发生一样!

    让我知道结果如何。

答案 2 :(得分:0)

这已在latest version of the SDK中修复。只需使用IGraphResult的Texture字段。

FB.API("/me/picture", HttpMethod.GET, delegate(IGraphResult result) {
  if (result.Texture != null) {
    // use texture
  }
});