【问题标题】:adding a Post To Facebook Timeline from iOS APP从 iOS APP 将帖子添加到 Facebook 时间线
【发布时间】:2013-08-30 23:30:31
【问题描述】:

您好,我正在尝试启用 IBAction,以便在用户的时间线上发布,而他们有一个活动部分。我收到一条错误消息,说明;函数“x”的隐式声明在 C99 中无效。我一直在阅读有关该问题的帖子,但没有运气,老实说,我不确定我是否做对了。我更新了我的 fb 应用程序的权限,并从 Graph API Explorer 获取了目标代码,但我不知道我是否在我的代码上正确实现了它。

这是我的发帖方法:

-(void) aPost
{
    NSMutableDictionary<FBGraphObject> *object =
    [FBGraphObject openGraphObjectForPostWithType:@"website"
                                            title:@"CR Taxi APP"
                                            image:@"http://a4.mzstatic.com/us/r1000/047/Purple4/v4/05/cc/f2/05ccf23f-a409-1e73-a649-a5e6afc4e6eb/mzl.llffzfbp.175x175-75.jpg"
                                              url:@"https://itunes.apple.com/cr/app/cr-taxi/id674226640?mt=8"
                                      description:@"La nueva aplicación para llamar taxis!"];;

    [FBRequestConnection startForPostWithGraphPath:@"{id_from_create_call}"
                                       graphObject:object
                                 completionHandler:^(FBRequestConnection *connection,
                                                     id result,
                                                     NSError *error) {
                                     // handle the result
                                 }];

}

这是我的行动方法

- (IBAction)publishAction:(id)sender {

    if ([FBSession.activeSession.permissions
         indexOfObject:@"publish_actions"] == NSNotFound) {

        NSArray *writepermissions = [[NSArray alloc] initWithObjects:
                                     @"publish_stream",
                                     @"publish_actions",
                                     nil];


        [[FBSession activeSession]requestNewPublishPermissions:writepermissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *aSession, NSError *error){
            if (error) {
                NSLog(@"Error on public permissions: %@", error);
            }
            else {
             **not on the code //( error on this one)   aPost(aSession, error);
            }


        }];

    }
    else {
        // If permissions present, publish the story
     **not on the code //(not an error on this one)  aPost(FBSession.activeSession, nil);
    }


}

请帮忙!

谢谢!

【问题讨论】:

    标签: ios xcode facebook api post


    【解决方案1】:

    我猜编译器错误实际上是“函数 'aPost' 的隐式声明是无效的 C99”,尽管您的操作方法代码的格式在编写时是不稳定的。编译器只会在第一次遇到对 aPost 的函数调用时生成该错误消息。

    aPost 被编写为一个没有返回值且不接受参数的方法。您试图将其作为 C 函数调用,并向其传递两个参数,编译器将其解释为一个全新的函数。由于 aPost 是用所有硬编码字符串编写的,您可能只想更改对 aPost(arg1, arg2); 的调用。给[自己发帖]; (前提是 aPost 和 publishAction 属于同一类)。

    【讨论】:

      【解决方案2】:

      试试这个:可能对你有帮助

      //在你的 ViewController.h 文件中写入这一行

          @property (strong, nonatomic) NSMutableDictionary *postParams;
      

      //在查看Controller.m文件中

      - (void)viewDidLoad
        {
           self.postParams =
           [[NSMutableDictionary alloc] initWithObjectsAndKeys:
       [UIImage imageNamed:@"Default.png"], @"picture",
       @"Facebook SDK for iOS", @"name",
       @"build apps.", @"caption",
       @"testing for my app.", @"description",
       nil];
      
      [self.postParams setObject:@"hgshsghhgsls" forKey:@"message"];
      
       }
       - (IBAction)SharePressed:(id)sender {
      
       @try {
      
      
          [self openSession];
          NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists",@"read_stream", nil];
      
             [[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
                                                     completionHandler:^(FBSession *session, NSError *error) {
                                                         /* handle success + failure in block */
                                                         if (![session isOpen]) {
                                                             [self openSession];
                                                         }
                                                     }];
      
          [FBRequestConnection   startWithGraphPath:@"me/feed" parameters:self.postParams HTTPMethod:@"POST"
                                  completionHandler:^(FBRequestConnection *connection,id result,NSError *error) {
                                      NSString *alertText;
                                      if (error) {                                               
                                        alertText = [NSString stringWithFormat:@"error: domain = %@, code = %d, des = %@",error.domain, error.code,error.description];  
                                      }
                                      else
                                      {
                                          alertText=@"Uploaded Successfully";
                                          [self ResetAllcontent];
                                      }
                                      // Show the result in an alert
                                      [[[UIAlertView alloc] initWithTitle:@"Result" message:alertText delegate:self cancelButtonTitle:@"OK!"
                                                        otherButtonTitles:nil]show];
                                  }]; 
      
      
      
      
      
      }
      @catch (NSException *exception) {
          UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please Login" message:@"For Sharing on facbook please login with facbook" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
          [alert show];
      }
      @finally {
      }
      }
      
      - (void)openSession
       {
          AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
      
      [FBSession openActiveSessionWithReadPermissions:nil
                                         allowLoginUI:YES
                                    completionHandler:
       ^(FBSession *session,
         FBSessionState state, NSError *error) {
           [appDelegate sessionStateChanged:session state:state error:error];
       }];
      
      ACAccountStore *accountStore;
      ACAccountType *accountTypeFB;
      if ((accountStore = [[ACAccountStore alloc] init]) &&
          (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){
      
          NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
          id account;
          if (fbAccounts && [fbAccounts count] > 0 &&
              (account = [fbAccounts objectAtIndex:0])){
      
              [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
                  //we don't actually need to inspect renewResult or error.
                  if (error){
      
                  }
              }];
          }
      }
      }
      }
      

      //=====在您的 plist 文件中执行 URLTypes=>Item 0=> URL Schemes =>Item 0=>fbyourfacebookId

      FacebookAppID-你的 facebookID

      是的,别忘了在 developer.facebook.com 上创建 facebook id 并根据需要授予权限

      【讨论】:

      • 嗨 Chitra,谢谢你回答我的问题,虽然我试过了,只是遇到了一堆其他错误。从 postParams 开始,我对整个 facebook 发布真的很陌生......你有什么办法可以更详细地解释我需要做什么?我真的很感激!
      • 你在 plist 文件中添加了 facebook id 吗?或者我需要用步骤显示吗?
      【解决方案3】:
      - (IBAction)shareViaFacebook:(id)sender {
      
      
      if (FBSession.activeSession.isOpen) {
          NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         [NSString stringWithFormat:@"%@.  Join on Linute.",self.userNameLabel.text], @"name",
                                         //@"Build great social apps and get more installs.", @"caption",
                                         locationString, @"description",
                                         //@"http://www.linute.com/", @"link",
                                         eventPicString, @"picture",//imageURL
                                         nil];
      
          // Make the request
          [FBRequestConnection startWithGraphPath:@"/me/feed"
                                       parameters:params
                                       HTTPMethod:@"POST"
                                completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                    if (!error) {
                                        // Link posted successfully to Facebook
                                        NSLog(@"result: %@", result);
                                    } else {
                                        // An error occurred, we need to handle the error
                                        // See: https://developers.facebook.com/docs/ios/errors
                                        NSLog(@"%@", error.description);
                                    }
                                }];
      }else{
      
          FBSession *session = [[FBSession alloc] initWithPermissions:@[@"public_profile", @"email",@"user_friends",@"publish_actions"]];
          [FBSession setActiveSession:session];
      
          [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
      
              if (FBSession.activeSession.isOpen) {
      
                  [self shareViaFacebook:nil];
      
              }else{
                  [self shareViaFacebook:nil];
      
      
              }
          }];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多