Note that there are some explanatory texts on larger screens.

plurals
  1. PORequest a Page Access Token in C# SDK
    primarykey
    data
    text
    <p>As a proof of concept for a simple background application, I used the Graph API Explorer to create an access token for my app to post something to the wall of a page I maintain. It worked fine. Naturally, however, the token expires.</p> <p>So now I'm trying to have the background application automatically request a new page access token each time it runs. And I'm having a lot of trouble finding a concrete definition of how to do that. There's no shortage of information regarding Facebook and Access Tokens, but nothing seems to demonstrate how to have a background application post to a page. (Not post to a user's wall, not display a login dialog to a user since it's a background application, etc.)</p> <p>I can fetch an access token in code easily enough by reading the response from a web request to this URL:</p> <pre><code>https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&amp;client_id={MY_APP_ID}&amp;client_secret={MY_APP_SECRET} </code></pre> <p>Of course, that "access token" doesn't work when trying to post to the page's wall. It says that the user hasn't authorized the application to perform this action. The action I'm performing is pretty simple:</p> <pre><code>var client = new FacebookClient(GetFacebookAccessToken()); dynamic parameters = new ExpandoObject(); parameters.message = "this is a test"; dynamic result = client.Post("{MY_PAGE_ID}/feed", parameters); </code></pre> <p>I've read in some places that I'll need to make a second request, using the first access token, to get the page access token. But I can't seem to find examples of how to do that.</p> <p>Can someone shed some light on this for me?</p> <ul> <li>I have a Facebook page.</li> <li>I have a Facebook app which serves no other purpose than to provide a means for a local background application to access said page.</li> <li>I just need that application to be able to authenticate so it can post something to the page.</li> <li>(And if there's a step I need to perform in the Facebook UI to permanently give the application permission to do this, I think I've performed that step but it would be good to double check somehow.)</li> </ul> <p><strong>Edit:</strong> It's been described to me that I need to obtain a long-lived user access token and, using that, obtain a page access token. The theory is that said page access token won't expire. However, what's not clear to me is how one accomplishes this.</p> <p>I've read <a href="https://developers.facebook.com/roadmap/offline-access-removal/" rel="nofollow">the page describing the deprecation of <code>offline_access</code></a>, as well as <a href="https://developers.facebook.com/docs/howtos/login/server-side-login/" rel="nofollow">the page describing server-side access</a>. However, I'm clearly misunderstanding something. In the former, it references the latter for obtaining the proper token. The latter, however, includes steps for presenting a login to the user, having them accept permissions, and using the response from that login.</p> <p>Being a background process that runs unattended, presenting any sort of question to a user (which would be me) isn't really an option. I've also been told that I can't do a one-time request from my browser to get an access token because that is, by definition, client-side interaction and not part of the necessary server-side flow. (It seems odd to me that the service would care if a RESTful request comes from a web browser vs. from an application, but I'm not familiar enough with OAuth or the Facebook API to really make that call.)</p> <p>So, if I can perform some manual steps to get a permanent access token for the app to post to the Facebook page, what are those steps? Conversely, if I can perform some automated steps in the application to acquire access each time it runs, what are those steps?</p> <p>(Making a few more API calls from the application adds a second or two of running time to an otherwise once-a-day process, so it makes no difference to me which approach to take.)</p>
    singulars
    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.
 

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