내가했던 어떤 종류의 유사한 경우 사용자가 내 mvc 응용 프로그램에서 "공유"버튼을 클릭하면, 그의 벽에 뭔가를 게시합니다. oauth 대화 상자를 사용하는 문제는 사용자가 로그인하여 응용 프로그램 권한을 수락 할 수 있도록 브라우저를 페이스 북 사이트로 리디렉션한다는 것입니다. 은 "공유"버튼을
는,이 URL로 연결 :
<a href=""https://www.facebook.com/dialog/oauth?client_id=[YOUR_APP_ID]&redirect_uri=[THE_REDIRECT_PAGE]/&scope=publish_stream"">
<img src='@Url.Content("~/Images/facebook_share.png")' alt="Share on Facebook!" style="height:28px" />
</a>
YOUR_APP_ID 당신의 페이스 북의 응용 프로그램 ID입니다. THE_REDIRECT_PAGE는 사용자가 로그인하고 권한을 수락하면 Facebook에서 자동으로 리디렉션되는 사이트의 공개 페이지입니다. 페이 스북이 리디렉션되면 "code"라는 쿼리 문자열 매개 변수가 추가됩니다. 참고 : 리디렉션 페이지는 "/"로 끝나야하며 문서로 끝날 수 없으며 그렇지 않으면 작동하지 않습니다!
사용자가 요청을 수락하면 액세스 코드라는 다른 코드를 페이스 북에 요청해야합니다.이 코드는 사용자의 벽에 게시하는 데 사용됩니다. 당신이 액세스 토큰이 있으면
public ActionResult Index(string code)
{
string fbAuthCode = Request["code"]; //The authorization code.
string fbAppId = "XXXXXXX"; //Your fb application id.
string fbSecretAppId = "XXXXXXXXXXXXXXXXXXXXX"; //Your fb secret app id, it is found on the fb application configuration page.
string redirectUrl = string.Format("[THE_REDIRECT_PAGE]", locationPointId, entryLocationId); //The redirect url. THIS MUST BE THE EXACT SAME REDIRECT URL USED ON THE JAVASCRIPT LINK!
string fbUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + fbAppId + "&redirect_uri=" + redirectUrl + "&client_secret=" + fbSecretAppId + "&code=" + fbAuthCode; //Url used to post.
string accessToken = string.Empty;
try
{
WebClient client = new WebClient();
using (Stream stream = client.OpenRead(fbUrl))
using (StreamReader reader = new StreamReader(stream))
{
accessToken = reader.ReadToEnd().Split('&')[0].Replace("access_token=", string.Empty);
reader.Close();
}
}
catch (Exception ex)
{
throw new Exception("An error ocurred while trying to get the fb token in " + fbUrl, ex);
}
, 당신은 사용자의 벽에 게시 할 수 있습니다 :
이
string postUrl = "https://graph.facebook.com/me/feed";
string postParameters;
postParameters = string.Format("message={0}&picture={1}&name={2}&caption={2}&description={3}&link={4}&access_token={5}",
"[Message]",
"[PictureUrl]",
"[Name]",
"[Caption]",
"[Link]",
accessToken);
try
{
System.Net.WebRequest req = System.Net.WebRequest.Create(postUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postParameters);
req.ContentLength = bytes.Length;
using (System.IO.Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
using (WebResponse resp = req.GetResponse())
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
ViewBag.PostResult = sr.ReadToEnd().Trim();
sr.Close();
}
os.Close();
}
}
catch (Exception ex)
{
throw new Exception("An error ocurred while posting data to the user's wall: " + postUrl + "?" + postParameters, ex);
}
return RedirectToAction(XXXXXXXXXXXxx....); //Then i redirect to another page.
당신은 내가 던질 예외에 그것을 볼 수 있습니다
이 코드는 리디렉션 페이지에 게시 된 URL (디버깅 목적). 해당 URL을 사용하면 일반적으로 페이스 북 그래프 API 탐색기 또는 Linter로 이동하여 실제 오류를 확인할 수 있습니다.
이것이 정확히 원하는지는 모르겠지만 킥오프를 제공하기를 바랍니다. 오픈 그래프의 페이스 북 문서가 아직 좋지 않기 때문에 나는 며칠 동안 고민했습니다. 우리를 위해 적어도 컬 : https://developers.facebook.com/docs/opengraph/
https://developers.facebook.com/docs/opengraph/tutorial/ 는 희망이 도움을 사용하지 않는. MT.