简体   繁体   English

从iOS APP添加到Facebook时间线

[英]adding a Post To Facebook Timeline from iOS APP

HI Im trying to enable a IBAction to post on an user's timeline while they have an active section. 即时消息试图使IBAction在用户具有活动部分时在其时间线上发布。 I am getting an error message stating; 我收到一条错误消息,指出: Implicit declaration of function "x" is invalid C99. 函数“ x”的隐式声明无效C99。 I been reading posts about the issue but no luck and honestly I am not sure if I am doing this right at all. 我一直在阅读有关此问题的帖子,但没有运气,说实话,我不确定自己是否正确地做到了。 I updated the permissions on my fb app and got the object code from the Graph API Explorer but I dont know if Im implementing it right on my code. 我更新了我的fb应用程序的权限,并从Graph API Explorer中获取了目标代码,但我不知道Im是否在我的代码上正确实现了它。

Here is my post method: 这是我的发布方法:

-(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
                                 }];

}

and this is my action method 这是我的行动方法

- (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);
    }


}

Please help! 请帮忙!

Thank you! 谢谢!

I'd guess the compiler error is actually "Implicit declaration of function 'aPost' is invalid C99", although the formatting of your action method code is wonky as written. 我猜编译器错误实际上是“函数'aPost'的隐式声明是无效的C99”,尽管您的操作方法代码的格式写得很奇怪。 The compiler is only going to produce that error message the first time it encounters the function call to aPost. 编译器仅在第一次遇到对aPost的函数调用时才会产生该错误消息。

aPost is written as a method that has no return and takes no arguments. aPost被编写为没有返回值且不带参数的方法。 You are trying to call it as a C function, passing it two arguments, which the compiler interprets as an entirely new function. 您试图将其称为C函数,并向其传递两个参数,编译器将其解释为全新函数。 As aPost is written with all the hard-coded strings, you probably just want to change the calls to aPost(arg1, arg2); 由于aPost是用所有硬编码的字符串编写的,因此您可能只想将调用更改为aPost(arg1,arg2);。 to [self aPost]; 去[自己邮寄]; (provided aPost and publishAction are in the same class). (提供的aPost和publishAction在同一类中)。

Try this: might helps you 试试这个:可能对您有帮助

//Write This Line in your ViewController.h File //将此行写入ViewController.h文件中

    @property (strong, nonatomic) NSMutableDictionary *postParams;

//in View Controller.m File //在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){

            }
        }];
    }
}
}
}

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

FacebookAppID-your facebookID FacebookAppID-您的facebookID

在此处输入图片说明 And yes dont forget to create facebook id at developer.facebook.com and also give permissions as your need 是的,别忘了在developer.facebook.com上创建Facebook ID,并根据需要提供权限

- (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];


        }
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM