如何通过iOS中的图形API从应用程序在Facebook页面上发布?

时间:2015-05-26 09:27:41

标签: ios iphone facebook facebook-graph-api

我想在Facebook页面上发帖作为页面帖子。我使用的是下面的图形代码API,但是当其他人发布时发布,而不是作为页面管理员/页面本身:

NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                             @"Testing Post", @"name",
                             @"This is testing", @"message",
                             @"this is description", @"description",                            
                             nil];  

 NSString *feed = [NSString stringWithFormat:@"/Page ID/feed"];

    [FBRequestConnection startWithGraphPath:feed
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {
                              if(!error){

                                  NSLog(@"%@", result);
                              }
                              else{
                                  NSLog(@"Error %@", error);

                                  }

                          }];

2 个答案:

答案 0 :(得分:1)

如果您想以网页形式发布,则需要使用具有 @Override public void onBackPressed() { try { //pop up Window closed. if (doubleBackToExitPressedOnce) { super.onBackPressed(); return; } this.doubleBackToExitPressedOnce = true; Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce=false; } }, 2000); } catch(Exception ex) { ex.printStackTrace(); } } 权限的网页访问权限。

答案 1 :(得分:1)

以下是完整答案

NSString *accesstoken = <Page_Access_Token>

  NSDictionary*  params = [NSDictionary dictionaryWithObjectsAndKeys:
              @"Post heading", @"name",
              accesstoken, @"access_token",
              @"Type post message", @"message",
              @"Hyperlink to your post", @"link",
              @"Add description", @"description",
              @"Image url string", @"picture",
              nil];

    FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
                                                        graphPath:@"/me/feed"
                                                       parameters:params
                                                       HTTPMethod:@"POST"];    

    FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
    [requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
     {
         if (!error) {             
             NSLog(@" %@", result);             
         }
         else
         {
             NSLog(@"%@", error);                        
         } 

     }];