从 iOS APP 将帖子添加到 Facebook 时间线

问题描述 投票:0回答:3

我正在尝试启用

IBAction
在用户有活动部分时在他们的时间轴上发布。我收到一条错误消息,指出:

函数“x”的隐式声明在 C99 中无效。

我一直在阅读有关这个问题的帖子,但没有运气,老实说,我不确定我是否做得对。我更新了 Facebook 应用程序的权限,并从 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 objective-c xcode facebook post
3个回答
0
投票

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

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


0
投票

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

//将此行写入 ViewController.h 文件中

    @property (strong, nonatomic) NSMutableDictionary *postParams;

//在View 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=>项目 0=> URL 方案 =>项目 0=>fbyyourfacebookId

FacebookAppID-您的facebookID

enter image description here 是的,不要忘记在developer.facebook.com 创建 facebook id 并根据您的需要授予权限


0
投票
- (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];


        }
    }];
}
© www.soinside.com 2019 - 2024. All rights reserved.