使用 W8/WP8 c# sdk 是否可以实现 facebook 用户对用户的请求?

Is facebook user to user request possible with W8/WP8 c# sdk?(使用 W8/WP8 c# sdk 是否可以实现 facebook 用户对用户的请求?)

本文介绍了使用 W8/WP8 c# sdk 是否可以实现 facebook 用户对用户的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的手机游戏邀请来自 facebook 的朋友,但我无法做到.我正在使用适用于 Windows 8 的 Facebook c# SDK(希望在准备好后移植到 WP8、Android 和 iOS),但问题是我对 facebook API 参数感到困惑:

I'm trying to get my mobile game to invite friends from facebook but I'm unable to. I'm using Facebook c# SDK for Windows 8 (hopefully porting when ready to WP8, Android and iOS) but the problem is I'm confused about the facebook API paremeters:

这是我的代码:

var fb = new FacebookClient (accessToken);
dynamic parameters = new ExpandoObject();
parameters.appId = facebookAppId;
parameters.message = "This is a test!";
parameters.to="friendID1,friendID2,...";

string request=String.Format ("/me/apprequests");
dynamic result = await fb.PostTaskAsync (request, parameters);

当我使用此代码时,发布任务正确完成,但是(检查结果变量并查看 facebook)我"用户收到了该邀请.to"字段似乎被忽略了,me"是唯一收到请求的人.

when I use this code, the Post task completes correctly, but (checking the result variable and looking at facebook) on the "me" user receives that invitation. The "to" field seems to be ignored and "me" is the only one receiving the request.

如果我使用

string request=String.Format ("/{0}/apprequests",FRIEND_ID);

而不是/me/apprequests,然后我收到以下错误:

instead of /me/apprequests, then I receive the following error:

OAuthException "(#2) 无法创建任何应用请求",

OAuthException "(#2) Failed to create any app request",

我在某些地方读到访问令牌必须是应用令牌,但文档说它应该只在您的服务器执行这些请求时使用,我想要的是用户对用户的请求,不是应用程序对用户的请求.

I've read in some places that the access token must be an App Token, but the documentation says that it should only be used when your server is doing those requests, What I want is a user-to-user request, not an app-to-user request.

到目前为止,我已经看到可以通过 Dialog Request 在 Android 和 iOS 中获取它,但我在 C# SDK 中没有找到它们,所以我尝试手动进行 apprequest,但没有运气.

So far I've seen it's possible to get it in Android and iOS via a Dialog Request, but I've not found them in the C# SDK, so I'm trying to make the apprequest manually, without luck.

是否可以在 Windows Phone 8 或 Windows 8 上使用它?怎么样?

Is it possible to get this working with Windows Phone 8 or Windows 8? How?

谢谢,卡克

推荐答案

是的,这是可能的.不幸的是,您不能通过 SDK 来实现,因为 Facebook 不允许您以编程方式发送请求.必须通过对话框请求框/弹出窗口来完成.

Yes it is possible. Unfortunately, you cannot do it via the SDK since Facebook doesnt allow you to send requests programatically. It has to be done through the dialog request box/popup.

因此,在尝试以下解决方案之前,请确保用户已登录.使用 LoginAsync 方法获取 facebook 访问令牌后,请按照以下步骤操作.

So, make sure the user is logged in before trying the following solution. After you get the facebook access token by using the LoginAsync method, follow these steps.

  1. 在启用脚本的 xaml 中创建 WebBrowser 控件.

<phone:WebBrowser Visibility="Collapsed" IsScriptEnabled="True" Name="FbBrowser"></phone:WebBrowser>

  1. 现在在您的代码中,创建一个字符串,其中包含您要邀请的用户的 facebook id,格式为id1,id2,id3".

  1. Now in your code behind, create a string with the facebook ids of the users you want to invite in CSV format like "id1,id2,id3".

将网络浏览器导航到以下页面并订阅导航事件:<代码>https://m.facebook.com/dialog/apprequests?"+ "message=your_message&app_id=" + "your_facebook_appid" + "&redirect_uri=https://m.facebook.com&to=" + user_facebook_ids_CSV + "&sdk=2&display=touch"

Navigate the web browser to the following page and subscribe to the navigating event: "https://m.facebook.com/dialog/apprequests?" + "message=your_message&app_id=" + "your_facebook_appid" + "&redirect_uri=https://m.facebook.com&to=" + user_facebook_ids_CSV + "&sdk=2&display=touch"

FbBrowser.Visibility = Visibility.Visible;FbBrowser.Navigating += FbBrowser_Navigating;FbBrowser.Navigate(url1);

  1. 您可以在导航事件中处理网页的成功和失败响应.

private void FbBrowser_Navigating(object sender, NavigatingEventArgs e){if (e.Uri.ToString().StartsWith("https://m.facebook.com/?error_code") || e.Uri.ToString().StartsWith("https://m.facebook.com/?要求")){FbBrowser.Visibility = Visibility.Collapsed;FbBrowser.Navigate(new Uri("about:blank"));
}}

这篇关于使用 W8/WP8 c# sdk 是否可以实现 facebook 用户对用户的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 W8/WP8 c# sdk 是否可以实现 facebook 用户对用户的请求?

基础教程推荐