0
我使用最新版本的Facebook SDK 4.1的IOS,但是當我上傳圖片和文字,它提供了一個error.Below是我的代碼 -得到錯誤,在Facebook上發佈IOS
的NSArray *權限= [[NSArray alloc] initWithObjects:@「publish_actions」,@「user_photos」,nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error)
{
if (error)
{
}
else if(FB_ISSESSIONOPENWITHSTATE(status))
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error)
{
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
imgShare,@"picture", txtViewPost.text,@"message",
nil];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/feed"
parameters:parameters
HTTPMethod:@"POST"];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:request
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
isFacebookActive = YES;
[btnFacebook setImage:[UIImage imageNamed:@"facebook-round-active-btn.png"] forState:UIControlStateNormal];
NSLog(@"Photo uploaded successfuly! %@",result);
}
else
{
NSLog(@"Photo uploaded failed :(%@",error.userInfo);
isFacebookActive = NO;
[btnFacebook setImage:[UIImage imageNamed:@"facebook-round--btn.png"] forState:UIControlStateNormal];
}
}];
[connection start];
}
}];
}
}];
下面是錯誤日誌
Photo uploaded failed :({
"com.facebook.sdk:ErrorSessionKey" = "<FBSession: 0x7fb7d20a3280, state: FBSessionStateOpen, loginHandler: 0x7fb7d0f40520, appID: 386374258207146, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x7fb7d0ea89b0>, expirationDate: 2015-07-12 08:31:47 +0000, refreshDate: 2015-05-13 14:30:50 +0000, attemptedRefreshDate: 0000-12-30 00:00:00 +0000, permissions:(\n \"user_location\",\n \"user_events\",\n \"user_photos\",\n \"user_videos\",\n \"user_friends\",\n email,\n \"publish_actions\",\n \"public_profile\"\n)>";
"com.facebook.sdk:HTTPStatusCode" = 400;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 100;
message = "(#100) picture is not properly formatted";
type = OAuthException;
};
};
code = 400;
};
}
什麼是'imgShare'?日誌中的錯誤是「圖片格式不正確」。 – Mike
imgShare是UIImage的對象。 –
如果我在尋找正確的文檔(https://developers.facebook.com/docs/reference/ios/3.5/class/FBRequest),它看起來像期待'image'成爲圖像的URL,而不是一個圖像對象。 – Mike