gpt4 book ai didi

facebook-graph-api - 访问 token 无限续订

转载 作者:行者123 更新时间:2023-12-04 07:52:53 26 4
gpt4 key购买 nike

我正在编写一个社交管理工具。我需要 Facebook 的无限访问 token 。

首先请告诉我我是否理解正确;
Access Token 我们得到的原因是为了能够拥有用户对应用程序的帐户权限,并且这个 Access Token 有 60 天的有效期。但即使在过期之后,应用程序上的用户帐户权限仍然只有我们无权访问它?

我可以在过期后更新访问 token 吗?我尝试过这样的事情;

 void GetToken()
{
try
{
WebClient webClient = new WebClient();

String fb_exchange_token = null;

fb_exchange_token = ds.Tables[0].Rows[0]["token"].ToString();
String newToken = fb_exchange_token;
var fb = new FacebookClient();
try
{
dynamic result = fb.Get("oauth/access_token", new
{
client_id = client_id,
client_secret = client_secret,
grant_type = "fb_exchange_token",
fb_exchange_token = fb_exchange_token
});
}
catch (Exception ex)
{
if (ex.Message.Contains("expired"))
{
dynamic result = fb.Get("oauth/access_token", new
{
client_id = client_id,
client_secret = client_secret,
grant_type = "client_credentials",
fb_exchange_token = fb_exchange_token
});

newToken = (string)result.access_token;
if (newToken != fb_exchange_token)
SqlHelper.ExecuteNonQuery(ConnectionString, "SocialTokenUpdate", ds.Tables[0].Rows[0]["SocialId"].ToString(), newToken);
}

DataProvider.ExceptionLogAdd("xx.aspx", "GetToken", ex.Message);
}



Session["Token"] = newToken;
Session["FBPageId"] = ds.Tables[0].Rows[0]["SocailFBId"].ToString();
}
catch (Exception ex)
{
DataProvider.ExceptionLogAdd("xx.aspx", "GetToken", ex.Message);
}
}

最佳答案

如果要自动生成新的 accessToken 意味着让应用程序打开用户授予应用程序访问权限的第一个屏幕。然后它会生成新的accessToken。如果 accessToken 过期,则在 OAuthException 中获取它并重定向到前屏。

关于facebook-graph-api - 访问 token 无限续订,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18333027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com