【问题标题】:NewMeRequest in the Facebook Android API in C#C# 中 Facebook Android API 中的 NewMeRequest
【发布时间】:2015-05-20 08:20:57
【问题描述】:

我一直在尝试通过以下代码在 Xamarin Studio 中使用适用于 Android 的 Facebook API 执行 Request.NewMeRequest:

Request.NewMeRequest (currentSession, new Request.IGraphUserCallback() {
    override void OnCompleted(IGraphUser user, Response Response){
        Console.WriteLine(user.FirstName);
    }
}).ExecuteAsync ();

但是 Xamarin Studio 给出了一些错误,所以我认为我在 C# 中没有以正确的方式这样做。有人有一些示例代码来说明如何执行此操作或解释为什么这不起作用?

提前致谢!

编辑: 感谢@Guilherme 的帮助,它现在没有返回任何错误,但我遇到了以下问题:

我已将代码更改为您的答案,如下所示:

public class MainActivity : Activity, ILocationListener, Request.IGraphUserCallback
{

    ...

    Session currentSession = Session.ActiveSession;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.Main);

        ...

        Console.WriteLine ("current session: " + currentSession.AccessToken);
        Request.NewMeRequest (currentSession, this).ExecuteAsync();
    }

    public void OnCompleted (IGraphUser user, Response response)
    {
        Console.WriteLine (user.Username);
    }

    ...

}

但现在它不会重新调整当前登录用户的用户名。会话不是问题,因为它是正确的。

【问题讨论】:

  • 你在使用Witch库吗?肯定这不会在 c# 上工作,因为它不支持匿名类。
  • 回调确实被调用了?
  • 没关系,现在可以了。 user.Username 为空,但用户对象拥有其余数据,因此我认为 Facebook 出于某种原因不会返回用户名。谢谢!

标签: c# android facebook facebook-graph-api xamarin


【解决方案1】:

这肯定不会在 c# 上工作,因为它不支持匿名类

让您的类实现 IGraphUserCallback 并将其作为参数传递,然后:

Request.NewMeRequest (currentSession, this).ExecuteAsync ();

【讨论】:

  • 感谢您的回复!你能帮我解决我添加到初始问题中的新问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多