我想在facebook页面中发布一篇作为管理员的帖子,其中用户是页面的管理员。我有来自
的页面访问令牌[FBRequestConnection startWithGraphPath:@"/me/accounts"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSString *token = [[[result objectForKey:@"data"] objectAtIndex:0] objectForKey:@"access_token"];//accessToken of the page
}];
现在我如何用这个令牌改变FBSession在页面上发布一个帖子作为一个管理员使用graphhapi ?FBDocumentation引用了openFromAccessTokenData。请帮助我,因为我被困在这个很长一段时间。我使用facebook sdk 3.2。提前感谢
NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:token, @"access_token",
titleCell.titleTextView.text,@"message",
[UserDefaultsManager fbPlaceId], @"place",
// fbPhotoId,@"object_attachment",
@"https://www.google.com",@"link",
photoUrl,@"picture",
titleCell.titleTextView.text,@"name",
typeCell.cellTextField.text,@"caption",
descriptionCell.descriptionTextView.text,@"description",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:@"/me/feed"
parameters:param
HTTPMethod:@"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if(!error)
{
NSLog(@"facebook result >> %@", result);
NSData *photoData = UIImagePNGRepresentation(promoImage);
NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:token,@"access_token",
photoData,@"source", nil];
FBRequest *requestToPostPhoto = [[FBRequest alloc] initWithSession:nil
graphPath:@"/me/photos"
parameters:param
HTTPMethod:@"POST"];
FBRequestConnection *requestToPostPhotoConnection = [[FBRequestConnection alloc] init];
[requestToPostPhotoConnection addRequest:requestToPostPhoto completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if(!error)
{
[loadingAlert dismissWithClickedButtonIndex:0 animated:YES];
NSLog(@"facebook result photo>> %@", result);
doneAlert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@""
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
if(self.isUpdatingPromo)
{
doneAlert.message = @"Promo updated successfully";
[doneAlert show];
}
else
{
doneAlert.message = @"Promo created successfully";
[doneAlert show];
}
}
else
{
[loadingAlert dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not post photo"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
}];
[requestToPostPhotoConnection start];
}
else
{
[loadingAlert dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not post"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
}];
[requestToPostConnection start];