OAuth 异常“需要访问令牌”当提供一个时
我正在使用 Facebook C# SDK 5.0.25。我正在尝试将照片上传到墙上,并且一直遵循“Samples/Facebook/Dynamic/GraphApi.cs”文档中给出的示例,但收到以下错误: “(OAuthException)需要访问令牌才能请求此资源”
我尝试了几种不同的解决方案,但最接近的是下面的代码,它给了我上述错误。
public static bool PostPNG(string UserID)
{
// sample usage: UploadPictureToWall(accessToken, @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg");
string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg";
var mediaObject = new FacebookMediaObject
{
FileName = System.IO.Path.GetFileName(filePath),
ContentType = "image/jpg"
};
mediaObject.SetValue(System.IO.File.ReadAllBytes(filePath));
//try
//{
var client = new FacebookClient(FBconstants.APP_ID, FBconstants.APP_SECRET);
string access_token = client.AccessToken;
client = new FacebookClient(access_token);
dynamic parameters = new ExpandoObject();
parameters.source = mediaObject;
parameters.message = "photo?";
parameters.access_token = access_token;
dynamic result = client.Post(UserID+"/photos", parameters);
PostDelete(result.id);
return true;
//}
//catch (FacebookApiException ex)
//{
// return false;
//}
}
我还发现,如果将“发布”命令切换为发布到“/feed”,则该命令会执行,但没有照片。 任何建议将不胜感激。
I'm using the Facebook C# SDK 5.0.25. I'm attempting to upload a photo to my wall, and I've been following the example given in the "Samples/Facebook/Dynamic/GraphApi.cs" document, but I'm receiving the following error:
"(OAuthException) An access token is required to request this resource"
I've tried several different solutions, but the closest I've come is the below code, which gives me the above error.
public static bool PostPNG(string UserID)
{
// sample usage: UploadPictureToWall(accessToken, @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg");
string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg";
var mediaObject = new FacebookMediaObject
{
FileName = System.IO.Path.GetFileName(filePath),
ContentType = "image/jpg"
};
mediaObject.SetValue(System.IO.File.ReadAllBytes(filePath));
//try
//{
var client = new FacebookClient(FBconstants.APP_ID, FBconstants.APP_SECRET);
string access_token = client.AccessToken;
client = new FacebookClient(access_token);
dynamic parameters = new ExpandoObject();
parameters.source = mediaObject;
parameters.message = "photo?";
parameters.access_token = access_token;
dynamic result = client.Post(UserID+"/photos", parameters);
PostDelete(result.id);
return true;
//}
//catch (FacebookApiException ex)
//{
// return false;
//}
}
I also found that if switched the Post command to post to "/feed" then the command executes, but without the photo.
Any suggestions would be greately appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我这里有一个 C# 工作代码示例,使用 Codeplex 的 Facebook C# SDK facebook Post image to wall
I have a working code sample here in C# using Facebook C# SDK from Codeplex facebook Post image to wall
确保您拥有发布流权限。
make sure you have the publish stream permission.