2010-09-03 21 views
0

我已將Facebook Connect添加到我的新iPhone應用程序。一切都很完美,沒問題。iPhone應用程序中Facebook-Api publish_stream的問題

但是,在這個應用程序中,我需要在用戶的牆上發佈任何對話框而不提示任何對話框。 我在Facebook文檔中搜索過,據我所知,如果我要求用戶給我正確的權限(在本例中爲publish_stream),對話框應該不會再出現。

但是儘管如此,盒子仍然出現。

我希望你能幫助我。

謝謝。

P.S.對不起,我的英文不好

回答

1

獲得publish_stream權限後使用圖形API。您將POST發送至:

https://graph.facebook.com/ID/feed 

此iPhone SDK本身不支持此操作,您必須自行實施此操作。您需要確保您創建正確的JSON編碼參數並確保它們正確地轉義。 從這開始的好地方是here

0

謝謝! 因此,如果我理解的很好,我必須這樣做:

使用此框架http://code.google.com/p/json-framework/可以添加JSON支持。

而這種代碼:

SBJSON *json = [SBJSON new]; 

    json.humanReadable = YES; 

    NSString *service = @"NameService"; 

    NSMutableDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: 
            @"MessaggeFromMyApp",@"message", 
            @"http://www.sample.com",@"link", 
            @"nomeOfTheLink",@"name", 
            @"captionOfTheLink",@"caption", 
            @"descriptionofTheLink",@"description", 
            @"MyDistrict",@"value", 
            @"2",@"txs_Action", 
            nil]; 
    //Pass it twice to escape quotes 
    NSString *jsonString = [NSString stringWithFormat:@"%@", [params JSONFragment], nil]; 

    NSString *changeJSON = [NSString stringWithFormat:@"%@", [jsonString JSONFragment], nil]; 

    NSLog(jsonString); 
    NSLog(changeJSON); 


    NSString *requestString = [NSString stringWithFormat:@"{\"id\":15,\"method\":\"%@\",\"params\":[%@]}",service,changeJSON,nil]; 
    NSLog(requestString); 


    NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]]; 


    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://graph.facebook.com/me/feed"]]; 

    NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]]; 
    [request setHTTPMethod: @"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPBody: requestData]; 

    //Data returned by WebService 
    NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ]; 
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding]; 

    NSLog(returnString); 

再次感謝您。

+0

這看起來不錯:)另外,如果我的回覆是你正在尋找的,不要忘記接受它作爲答案 – BeRecursive 2010-09-03 09:18:05

+0

當然,再次感謝。 下午我會測試代碼... – Sylter 2010-09-03 09:39:41