我想在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以使用GraphAPI作为管理员在页面上发布帖子? FBDocumentation对openFromAccessTokenData 引用了这个。请帮忙,因为我长期坚持这一点。我正在使用facebook sdk 3.2。提前致谢
答案 0 :(得分:3)
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];