我一直在使用Facebook C#SDK 5.1.1這個令人沮喪的問題。我已成功加載CSSilverlightFacebookApp並確認我的Facebook設置正常。我能夠讓測試應用程序顯示出來。使用Silverlight 3的Facebook畫布應用程序找不到HttpUtility
對於我的主機的情況下,我使用的是谷歌以下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))
該代碼似乎好工作,我得到傳入我的Silverlight代碼的oauth_token。下面的代碼工作到最後一行:
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( 「/我」),我得到一個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的所有組合,用於sl3和sl4的Facebook.dll。