WP7应用程序,WP7设备上的MethodAccessException,但在WP8设备上运行正常

时间:2013-07-16 09:55:33

标签: c# windows-phone-7 windows-phone-8 facebook-c#-sdk

就像标题所说的那样,我有一个wp7应用程序,当在WP7设备(lumia 800)上部署和调试时,在使用Facbook c#SDK但在WP8设备上部署和调试时,我得到一个MethodAccessException(lumia 920)它工作正常。这是错误发生的地方

private Uri GetURLLogin()
{     
  var fb = FacebookClient();
  return fb.GetLoginUrl(
       new {
            client_id = "blahblah",
            redirect_uri = "http://www.facebook.com/connect/login_success.html",
            response_type = "token",
            display = "popup",
            scope = "user_birthday, email"
           });   // Error occurs here
}

2 个答案:

答案 0 :(得分:3)

由于安全原因,Facebook.dll无法访问匿名对象属性。

尝试添加

[assembly: InternalsVisibleTo("Facebook")]

http://facebooksdk.net/docs/faq/

中的常见问题解答中提到了这一点

答案 1 :(得分:1)

试试这个

   private Uri GetFacebookLoginUrl(string appId, string extendedPermissions)
    {
        var fb = FacebookClient();
        var parameters = new Dictionary<string, object>();
        parameters["client_id"] = appId;
        parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
        parameters["response_type"] = "token";
        parameters["display"] = "touch";

        // add the 'scope' only if we have extendedPermissions.
        if (!string.IsNullOrEmpty(extendedPermissions))
        {
            // A comma-delimited list of permissions
            parameters["scope"] = extendedPermissions;
        }

        return _fb.GetLoginUrl(parameters);

    }

您需要提供App ExtendedPermissions

 private const string ExtendedPermissions = "user_about_me,read_stream,publish_stream,user_events,offline_access,user_activities,user_interests,user_likes,email,friends_birthday";

你的应用程序密钥由Facebook生成