2011-08-30 53 views
0

我一直在使用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。

回答

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 
    } 
相关问题