1

FBGraph api を使用して Facebook の壁をクリックすると Web サイトを開く Web サイトの画像と URL を表示する画像データを投稿する方法を教えてもらえますか?

ありがとう、

4

3 に答える 3

3

これを試して :

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_url,@"source",image_url, @"link",nil];
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
于 2012-12-14T08:17:55.277 に答える
2

皆さん、こんにちは。social.framework を使用して、画像データと URL を一緒に投稿できるようになりました。

プロジェクトに social.framework を追加し、ios6 で次のコードを実行してください。

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled) {

            NSLog(@"ResultCancelled");

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"There might be some problem in facebook posting please try agian later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];

            self.view.userInteractionEnabled = YES;
            [loadingView removeFromSuperview];

        } else

        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"We have checked in successfully on facebook." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];

            NSLog(@"Success");

            self.view.userInteractionEnabled = YES;
            [loadingView removeFromSuperview];

        }

        [controller dismissViewControllerAnimated:YES completion:Nil];
        [self uploadMessageToTwitter];

    };

    controller.completionHandler =myBlock;

    [controller addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/social-checkin/id504791401?mt=8"]];

    if (self.encoded_ImageData ==nil) {

        [controller addImage:[UIImage imageNamed:@"No_ImageFound.png"]];

    }
    else
    {

        [controller addImage:[UIImage imageWithData:self.encoded_ImageData]];

    }

    NSString *businessName;

    //Set business name string to be passed on facebook
    if (m_BusinessNameString == nil || [m_BusinessNameString isEqualToString:@""])
    {
        businessName = @"Business name not specified!";
    }
    else
    {
        businessName = [m_BusinessNameString uppercaseString];
    }

    NSString *nameString = [NSString stringWithFormat:@"CHECKED IN @"];

    //user has checked in with his friends if sc-merchant
    NSString *friendsString;

    if ([checkedFriendsNameArray count] > 0)
    {
        NSMutableString *checkedFriendsTempStr = [[NSMutableString alloc] init];

        for (NSMutableString *checkedStr in checkedFriendsNameArray)
        {

            [checkedFriendsTempStr appendString:[NSString stringWithFormat:@"%@,",checkedStr]];


            friendsString = [NSString stringWithFormat:@"WITH %@",checkedFriendsTempStr];
        }
    }
    else

    {
        friendsString = [NSString stringWithFormat:@"WITH NO FRIENDS"];

    }

    NSString *fname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userfname"];
    NSString *lname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userlname"];

    NSString *name=[fname stringByAppendingString:[NSString stringWithFormat:@"%@",lname]];


    NSString *main_TextString =[NSString stringWithFormat:@"%@ \n %@ %@ %@ %@",upperCaseStatusString,name,nameString,businessName,friendsString];

    [controller setInitialText:main_TextString];

    [self presentViewController:controller animated:YES completion:Nil];

}

else{

    NSLog(@"UnAvailable");
    self.view.userInteractionEnabled = YES;
    [loadingView removeFromSuperview];
}
于 2012-12-15T08:17:43.240 に答える
1

そのようにfbgraph経由で画像を送信してみてください:

- (IBAction)buttonClicked:(id)sender
{
    NSArray* permissions = [[NSArray alloc] initWithObjects:
                            @"publish_stream", nil];
    [facebook authorize:permissions delegate:self];
    [permissions release];

}
- (void)fbDidLogin
{
      NSString *filePath =yourpathToImage;
       NSData *videoData = [NSData dataWithContentsOfFile:filePath];
       NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, yourpathToImage,
                                   @"picture/jpeg", @"contentType",
                                   @"Video Test Title", @"title",
                                   @"Video Test Description", @"description",
                                   nil];
    [facebook requestWithGraphPath:@"me/photos"
                         andParams:params
                     andHttpMethod:@"POST"
                       andDelegate:self];
 }
于 2012-12-14T08:18:14.783 に答える