Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebookWebContext.Current.IsAuthorized works on one page but not another
    primarykey
    data
    text
    <p>I'm having some trouble getting my C# Facebook canvas app to determine if a user has authorized my app.</p> <p>The problem is actually only occurring on a secondary page. My app initially checks on the landing page and properly determines that the user has validated the application. </p> <p>Short overview of app:</p> <ol> <li>User likes app.</li> <li>User authorizes app.</li> <li>User sends info to a friend (via Facebook notification)</li> <li>Friend of user visits app and gets information.</li> </ol> <p>So steps 1-3 work. Step 4 is where I'm having some issues.</p> <p>I'm calling a method called "HasAuthorizedApplication" to ensure that the user has authorized the app before trying to get data from the API.</p> <pre><code>public bool HasAuthorizedApplication() { bool returnValue = false; try { if (FacebookWebContext.Current != null) { returnValue = FacebookWebContext.Current.IsAuthorized(Scope.Split(',')); if (returnValue) { AccessToken = FacebookWebContext.Current.AccessToken; HttpContext.Current.Session["accesstoken"] = AccessToken; } else { HttpContext.Current.Session["accesstoken"] = null; } } } catch { returnValue = false; } return returnValue; } </code></pre> <p>"Scope" is just the permissions I'm asking for: "publish_stream,email"</p> <p>So in step 4, the 'friend of the user' clicks on the Facebook notification and hits the landing page of the app. It checks for authorization and if the friend hasn't authorized, the auth dialog is presented. </p> <p>After authorizing, the app redirects to the secondary page and before I get the details of the notification from the graph, I check again to ensure the friend has still authorized the app.</p> <p>Unfortunately, when I call it this time, "FacebookWebContext.Current.IsAuthorized" always returns "false." I note that the "AccessToken" and "SignedRequest" are null at this time. I attempt to redirect back to the authorization dialog, but as the friend has already validated, it doesn't show to the user. But each time they return back to my secondary page, the "IsAuthorized" call returns false. (and if I try to just get the data, additionally returns false)</p> <p>My call to get the data surrounding the Facebook notification:</p> <pre><code>public dynamic GetData(string dataId) { if (HasAuthorizedApplication()) { var fb = new FacebookWebClient(AccessToken); dynamic data = fb.Get(dataId); return data; } return null; } </code></pre> <p>Where "dataId" is the id of the notification.</p> <p>Admittedly, I don't know much about how the interactions between the Javascript and backend work. I additionally have the following Javascript on both the landing and secondary pages:</p> <pre><code>&lt;script type="text/javascript"&gt; FB.init({ appId: '&lt;%=APPID %&gt;', status: true, // check login status cookie: true, // enable cookies to allow the server to access the session oauth: true, xfbml: true // parse XFBML }); &lt;/script&gt; </code></pre> <p>And ideas why it would work properly on one page and not another?</p> <p>Thanks! Craig</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload