[英]How to make an “apprequest” with c# Facebook SDK?
I would like to make an apprequest from my application using the c# facebook sdk. 我想使用c#facebook sdk从我的应用程序中提出要求。
After some investigation I found some examples that are using the app access token which has the following format : access_token = YOUR_APP_ID|YOU_APP_SECRET 经过一番调查,我发现了一些使用应用程序访问令牌的示例,其格式如下:access_token = YOUR_APP_ID | YOU_APP_SECRET
Now I have tried the following using the appAccessToken: 现在,我已尝试使用appAccessToken进行以下操作:
string appAccessToken = String.Format("{0}|{1}",Constants.FacebookAppId,Constants.FacebookAppSecret);
FacebookClient fb = new FacebookClient(appAccessToken);
fb.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
return;
}
};
dynamic parameters = new ExpandoObject();
parameters.message = "Test: Action is required";
parameters.data = "Custom Data Here";
fb.PostTaskAsync(String.Format("{0}/apprequests", Constants.FacebookAppId), parameters);
But it doesn't work... Is it possible to make an apprequest using the c# Facebook skd? 但这不起作用...是否可以使用c#Facebook skd进行申请? I hope anybody can help me.
我希望有人能帮助我。
Have a nice day! 祝你今天愉快! With best regards, Matthias
最好的问候,Matthias
To get access token of App. 获取App的访问令牌。 Just use this link and you will get it
只需使用此链接,您会得到它
https://developers.facebook.com/tools/access_token/ https://developers.facebook.com/tools/access_token/
Please check this out : http://facebooksdk.net/docs/phone/tutorial . 请检查以下内容: http : //facebooksdk.net/docs/phone/tutorial 。
To get user access token 获取用户访问令牌
Add this to App.xaml.cs 将此添加到App.xaml.cs
internal static string AccessToken = String.Empty;
internal static string FacebookId = String.Empty;
public static bool IsAuthenticated = false;
public static FacebookSessionClient FacebookSessionClient = new FacebookSessionClient(Constants.FacebookAppId);
Create a method to get Access token 创建一种获取访问令牌的方法
private async Task Authenticate()
{
try
{
_session = await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream");
App.AccessToken = _session.AccessToken;
App.FacebookId = _session.FacebookId;
}
catch (InvalidOperationException e)
{
var messageBox = new OneButtonCustomMessageBox
{
TbMessageTitle = { Text = "Facebook Login Error" },
TbMessageContent = {Text = e.Message}
};
messageBox.Show();
}
}
After you have Access Token you will use a method like this to call GraphAPI from FB to get user information 获得访问令牌后,将使用类似的方法从FB调用GraphAPI以获取用户信息
private async void LoadUserInfo()
{
var fb = new FacebookClient(App.AccessToken);
fb.GetCompleted += (o, e) =>
{
if (e.Error != null)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
return;
}
var result = (IDictionary<string, object>)e.GetResultData();
Dispatcher.BeginInvoke(async () =>
{
var profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", App.FacebookId, "normal", App.AccessToken);
this.ImgAvatar.Source = new BitmapImage(new Uri(profilePictureUrl));
this.TxtName.Text = String.Format("{0}", (string)result["name"]);
});
};
await fb.GetTaskAsync("me");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.