简体   繁体   中英

C# Posting on facebook page without login

So I'm posting on a facebook page through an application, but when i'm not logged in the application asks me to login first, can i run the application without having to login to my account to post on my page?

here's part of my code

string app_id = "app_id";
string app_secret = "app_secret";
string scope = "publish_stream,manage_pages,share_item,offline_access";

if (Request["code"] == null)
{
    Response.Redirect(string.Format(
        "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
        app_id, Request.Url.AbsoluteUri, scope)); //here it requests me to login
}
else
{
    //rest of code here
}

You must use the accesstoken via authresponse you received when the user you are trying to post on behalf of authorized your application. This token can be stored and used for your posting needs.

you can use FB.getLoginStatus which will return 'connected' if they have given authorization to your application then you use

var uid = response.authResponse.userID; var accessToken = response.authResponse.accessToken;

to retrieve the data you need

EDIT: the page that your " https://graph.facebook.com/oauth/authorize " call returns to [redirect_uri] will contain data called the accesstoken and userID, store these in your application. This userid's accesstoken does not expire and can be used for the future calls to post messages. did I explain better, if not please let me know what part is still unclear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM