2012-06-20 138 views
-2

我想發佈在頁面牆上的影像,我知道如何張貼在專輯中的圖像,以及用戶反饋,但對於頁面的給予一定的問題上傳照片至Facebook頁面

我使用FBGraph API並希望將照片上傳到Facebook頁面,可以通過提供指向任何教程或任何代碼庫的鏈接指導我。

目前我發佈的所有圖片都顯示在我的牆上,而不是我要發佈的頁面。

我用用上面的代碼的成功發佈文字頁面牆上,但不是像下面的代碼

 
-(void)postPictureToWall 
{ 
    NSMutableDictionary *variables = [[NSMutableDictionary alloc] init]; 

    //create a FbGraphFile object insance and set the picture we wish to publish on it 
    UIImage *frontImageNew=self.imgvgalleryImage.image; 

    FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:frontImageNew]; 

    //finally, set the FbGraphFileobject onto our variables dictionary.... 
    [variables setObject:graph_file forKey:@"file"]; 

    NSDateFormatter *df = [[NSDateFormatter alloc]init]; 
    [df setDateStyle:NSDateFormatterMediumStyle]; 
    [df setTimeStyle:NSDateFormatterMediumStyle]; 

    NSString *bodyString=[NSString stringWithFormat:@"%@",[df stringFromDate:[NSDate date]]]; 

    [variables setObject:bodyString forKey:@"message"]; 

FbGraphResponse *fb_graph_response = [objFBGraph doGraphPost:@"pageid_here/feed" withPostVars:variables]; 
SBJSON *parser = [[SBJSON alloc] init]; 
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil]; 
    NSLog(@"fb response = %@",facebook_response); 

} 

上午

回答

0

您可以使用此ASIHTTPRequest.Try做了爲我的代碼工作。

- (IBAction爲)shareClicked:(ID)發送 {

// if (selectedImage) { 
//  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Social Plus" 
//              message:@"Please select an image to share" 
//              delegate:self 
//            cancelButtonTitle:@"OK" 
//            otherButtonTitles:nil]; 
//  [alert show]; 
// } 
// else { 
//   

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"f_selected" ofType:@"png"]; 
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me/photos"]]; 
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
    request.delegate = self; 
    [request addFile:filePath forKey:@"file"]; 
    [request setPostValue:@"here will be the caption" forKey:@"message"]; 
    [request setPostValue:[[NSUserDefaults standardUserDefaults]objectForKey:@"access_token"] forKey:@"access_token"]; 
    [request setAllowCompressedResponse:NO]; 
// [request setTimeOutSeconds:60]; 

    [request setDidFinishSelector:@selector(uploadRequestFinished:)]; 
    [request startAsynchronous]; 
// } 
} 

-(void)uploadRequestFinished:(ASIHTTPRequest *)request 
{ 

    NSString *responseStr = [request responseString]; 
    NSLog(@"%@",responseStr); 
} 
+0

我使用確切的代碼只有一個區別,我使用'facebook_PAGE_ID'在me'的'的地方。但似乎無論它只發布在「我」上。你知道任何這樣的限制或facebook的API行爲不當嗎? – thesummersign