2012-11-07 33 views
2

我想張貼在Facebook好友的牆上張貼,我想這兩種方法,但沒有工作:Facebook好友的牆通過ID

1.

//post on wall 
NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:1]; 
[variables setObject:@"v" forKey:@"message"]; 

[graphref doGraphPost:[NSString stringWithFormat:@"1389799421/feed"] withPostVars:variables]; 
//post on wall 

2.

[_facebook requestWithGraphPath:@"1389799421/feed" 
         andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post" forKey:@"message"] 
        andHttpMethod:@"POST" 
        andDelegate:self]; 

...我不明白爲什麼!在Facebook網站上,我添加了該軟件包和權限。

+0

我不認爲Facebook好心地寫人程序自動caly發佈到牆壁上。你在這裏打一場艱苦的戰鬥......你還有什麼目的可以做到這一點,然後生成垃圾郵件? – gbtimmon

+0

你只是想發送一個裸貼到Facebook服務器,並期待它實際上張貼到牆上?如果是這樣,你幾英里遠離這個工作。在您嘗試發送此帖子之前,您如何驗證您的連接/會話? – gbtimmon

+0

好吧,我使用最初的HelloFacebook示例登錄到Facebook。我知道這不是最好的解決方案,但重要的是,據我所知,無法發送消息,並且沒有任何Facebook請求的示例代碼! – Alessandro

回答

2

我想張貼在Facebook好友的牆上

Facebook最近在開發者博客中宣佈,通過該API will not be possible any more from Feb 2013 on張貼到其他用戶的牆:

刪除功能通過圖形API發佈到朋友牆上

我們將刪除通過Graph API發佈給用戶朋友牆的功能。具體而言,針對[user_id]/feed其中[user_id]不同於會話用戶的帖子,或者target_id用戶與會話用戶不同的stream.publish調用將失敗。如果你想讓人們張貼他們的朋友的時間表,請調用feed dialog

所以我覺得現在開始開發這樣的功能非常沒用。

1

首先,您必須使用發佈權限打開您的會話。具體而言,您必須請求publish_stream權限。

NSArray * permissions = [[NSArray alloc] initWithObjects:@"publish_stream", nil]; 
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
    [self sessionStateChanged:session 
         state:status 
         error:error]; 
}]; 

如果您有發佈權限,則可以創建併發送請求。確保包含access_token作爲參數之一。如果你不這樣做,你會得到認證錯誤。

NSDictionary * postParameters = [NSDictionary dictionaryWithObjectsAndKeys:_textView.text, @"message", FBSession.activeSession.accessToken, @"access_token", nil]; 
NSString * graphPath = @"ID_NUMBER_HERE/feed"; 
FBRequest * request = [FBRequest requestWithGraphPath:graphPath parameters:postParameters HTTPMethod:@"POST"]; 
[[request initWithSession:FBSession.activeSession graphPath:graphPath parameters:postParameters HTTPMethod:@"POST"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    NSLog(@"Successful posted to Facebook"); 
    }]; 
} 
+0

同樣如CBroe所述,您現在不想構建此API調用,因爲它很快就會消失。 –