是否可以使用 W8/WP8 c# sdk 进行 Facebook 用户到用户请求? [英] Is facebook user to user request possible with W8/WP8 c# sdk?

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

问题描述

我正在尝试让我的手机游戏从 Facebook 邀请朋友,但我无法做到.我正在使用 Facebook c# SDK for Windows 8(希望在准备好移植到 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);

当我使用此代码时,Post 任务正确完成,但是(检查结果变量并查看 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.

到目前为止,我已经看到可以通过对话框请求在 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,以 CSV 格式(如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".

将 Web 浏览器导航到以下页面并订阅导航事件:<代码>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 用户到用户请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆