我使用Xamarin.Social组件在Facebook上发帖。它没有给出任何错误但没有发布任何内容。 我如下所述登录Facebook。
这是用CustomRenderer
写的登录页面
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
var activity = this.Context as Activity;
var auth = new OAuth2Authenticator (
clientId: "XXXXXXXXXXXXX",
scope: "email + public_profile + publish_actions",
authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri ("http://www.XXXXXXX.sv/"));
auth.Completed += (sender, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
//UserInfo is a static class which will hold the account object.
UserInfo.oFaceBookAccount = eventArgs.Account;
App.SuccessfulLoginAction.Invoke();
string _token = eventArgs.Account.Properties["access_token"];
App.SaveToken(_token);
}
else
{
// The user cancelled
}
};
activity.StartActivity(auth.GetUI(activity));
}
成功登录后,系统会将用户带到登陆屏幕。从用户点击一个按钮,该按钮将在Facebook上发布某些信息(链接)。
这是我用来在Facebook上发布信息的代码:
MagingCenter.Subscribe<ProfilePage, Messanger> (this, "onFaceBookShare", async (sender, args) =>
{
try
{
var Facebook = new FacebookService ();
Facebook.ClientId = "XXXXXXXX"; //it is same as i used while login
Facebook.RedirectUrl = new Uri ("http://www.XXXXXX.com/");
var item = new Xamarin.Social.Item (){ Text = "Test Msg." };
item.Links.Add (new Uri ("http://www.t.sv/"));
var account = UserInfo.oFaceBookAccount;
Facebook.ShareItemAsync (item, account);
} catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
});
请告诉我现有代码的问题。
感谢。