我一直在使用Facebook C#SDK的5.1.1这个非常令人沮丧的问题。我已成功加载CSSilverlightFacebookApp并确认我的Facebook设置正常。我能够让测试应用程序显示出来。
对于我的托管方案,我使用以下Google App Engine示例:
def load_signed_request(signed_request):
"""Load the user state from a signed_request value"""
global APP_ID, APP_SECRET
try:
sig, payload = signed_request.split(u'.', 1)
sig = base64_url_decode(sig)
data = json.loads(base64_url_decode(payload))
expected_sig = hmac.new(
APP_SECRET, msg=payload, digestmod=hashlib.sha256).digest()
# allow the signed_request to function for upto 1 day
if sig == expected_sig and \
data[u'issued_at'] > (time.time() - 86400):
return (data, data.get(u'user_id'), data.get(u'oauth_token'))
except ValueError, ex:
pass # ignore if can't split on dot
class MainHandler(webapp.RequestHandler):
def post(self):
global APP_ID, APP_SECRET
(ignore, ignore, oauth_token) = load_signed_request(self.request.get('signed_request'))
if oauth_token:
path = os.path.join(os.path.dirname(__file__), 'templates/silverlight.html')
params = dict(access_token=oauth_token)
self.response.out.write(template.render(path, params))
该代码似乎工作正常,我将oauth_token传递给我的Silverlight代码。下面的代码直到最后一行:
var token = "";
if (App.Current.Resources.Contains("token") && App.Current.Resources["token"] != null)
token = App.Current.Resources["token"].ToString();
if (!string.IsNullOrEmpty(token))
{
fb = new FacebookClient(token);
fb.GetCompleted += (o, args) =>
{
if (args.Error == null)
{
var result = (IDictionary<string, object>)args.GetResultData();
//Dispatcher.BeginInvoke(() => InfoBox.ItemsSource = result);
}
else
{
// TODO: Need to let the user know there was an error
//failedLogin();
}
};
// Making Facebook call here!
fb.GetAsync("/me");
}
在fb.GetAsync(“/ me”)上,我得到一个TypeLoadException,说它无法找到HttpUtility:
System.TypeLoadException was unhandled by user code
Message=Could not load type 'System.Net.HttpUtility' from assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
StackTrace:
at FluentHttp.HttpHelper.UrlEncode(String s)
at Facebook.FacebookUtils.GetUrl(IDictionary`2 domainMaps, String name, String path, IDictionary`2 parameters)
at Facebook.FacebookClient.GetUrl(String name, String path, IDictionary`2 parameters)
at Facebook.FacebookClient.BuildRootUrl(HttpMethod httpMethod, String path, IDictionary`2 parameters)
at Facebook.FacebookClient.PrepareRequest(String path, IDictionary`2 parameters, HttpMethod httpMethod, Stream& input, IDictionary`2& mediaObjects)
at Facebook.FacebookClient.ApiAsync(String path, IDictionary`2 parameters, HttpMethod httpMethod, Object userToken)
at Facebook.FacebookClient.GetAsync(String path, IDictionary`2 parameters, Object userToken)
at Facebook.FacebookClient.GetAsync(String path, IDictionary`2 parameters)
at Facebook.FacebookClient.GetAsync(String path)
at TicTacToe10.Page.Page_Loaded(Object sender, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
InnerException:
我已经确认我已经包含了System.Windows.dll和System.Net.dll。问题是什么?在我看来,我的代码与CSFacebookSilverlightApp示例完全相同。我还认为它可能与我使用Silverlight 3而不是4有关,但我已尝试将所有3和4的组合与Facebook.dll for sl3和sl4。
答案 0 :(得分:0)
事实证明,我的Silverlight项目缺少SILVERLIGHT编译符号(可能是因为我最初在MonoDevelop中创建它)。这导致Facebook SDK在错误的地方寻找HttpUtility。以下是Facebook SDK中的代码,它指出了解决方案:
public static string UrlEncode(string s)
{
#if WINDOWS_PHONE
return System.Net.HttpUtility.UrlEncode(s);
#elif SILVERLIGHT
return System.Windows.Browser.HttpUtility.UrlEncode(s);
#else
return UrlEncode(s, Encoding.UTF8);
#endif
}