在用户使用OAuth2Authenticator登录其Facebook帐户后,我写了一些代码来分享帖子。用户可以通过Facebook登录页面登录,但是在单击登录按钮后,它只会返回空白屏幕,并且不会在其帐户的Facebook上发布该帖子。
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
OAuth2Authenticator auth = new OAuth2Authenticator(
fbClientID,
"",
new Uri("https://m.facebook.com/dialog/oauth/"),
new Uri("https://www.facebook.com/connect/login_success.htmlRemove")
);
var intent = auth.GetUI(this);
Android.App.Application.Context.StartActivity(intent);
auth.Completed += AuthCompleted;
}
private void AuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
if (e.IsAuthenticated)
{
Share(e.Account);
}
else
{
// The user is not authenticated
}
}
private void Share(Xamarin.Auth.Account account)
{
// 1. Create the service
// fbClientID is a const string that is my clientID from
// developers.facebook.com
var facebook = new FacebookService { ClientId = fbClientID };
// 2. Create an item to share
var item = new Item { Text = "Hello World!" };
item.Links.Add(new Uri("google.com"));
facebook.ShareItemAsync(item, account);
}
有人可以让我知道我在这里做错了什么吗?我似乎找不到使用service.ShareItemAsync();
的任何示例项目。