3

私はiOS開発の初心者です。Facebookページに画像をアップロードしたい.画像がカメラから取得されたとき.このために、以下のコードを記述しますが、「このエンドポイントへの呼び出しにはFBSessionを指定する必要があります」というエラーが発生しました. 解決策を教えてください。

のような私のコード

-(IBAction)cameraButtonPressed:(id)sender
 {
if (FBSession.activeSession.isOpen)
{
    UIImage *uploadImage=[UIImage imageNamed:@"2.png"];
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:accesstoken, @"CAACEdEose0cBAAFiJ51qowOOBfOcobm1E3v1ZBZCNYBSZAyspbQCXPUZCdZC620bRWYvChxGd96ZAOSMNyRZA9TYd9teQ9Q1m67wKx0n66YjTiYZBxczKIZB7t3tuLO5RYsNbZBfGweZCenMXRF7xOBE6DQ6450nmB0hRJzI8PrT18WZAfU878GhNryp5Vw4Up3jGZCwPWmuMxDZAoZAXVosyZBNKQ6i",
                            postingString, @"message",uploadImage,@"source",
                            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)
     {
         NSLog(@"facebook result >> %@", result);
     }];
    [requestToPostConnection start];
}
else
{
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"user_likes",
                            @"read_stream",
                            @"publish_actions",
                            nil];
    FBSession *session = [[FBSession alloc] initWithPermissions:permissions];
    [FBSession setActiveSession:session];
}
if([FBSession openActiveSessionWithAllowLoginUI:NO])
{
    UIImage *uploadImage=[UIImage imageNamed:@"2.png"];
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:accesstoken, @"CAACEdEose0cBAAFiJ51qowOOBfOcobm1E3v1ZBZCNYBSZAyspbQCXPUZCdZC620bRWYvChxGd96ZAOSMNyRZA9TYd9teQ9Q1m67wKx0n66YjTiYZBxczKIZB7t3tuLO5RYsNbZBfGweZCenMXRF7xOBE6DQ6450nmB0hRJzI8PrT18WZAfU878GhNryp5Vw4Up3jGZCwPWmuMxDZAoZAXVosyZBNKQ6i",
                            postingString, @"message",uploadImage,@"source",
                            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)
     {
         NSLog(@"facebook result >> %@", result);
     }];
    [requestToPostConnection start];

}
else
{
    NSLog(@"Nothing to DO BYE");
}

ここで私のPListファイルは次のようになります

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string></string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb74549074886xxxx</string>
        </array>
    </dict>
</array>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>FacebookAppID</key>
<string>7454907xxxxxx</string>
<key>FacebookDisplayName</key>
<string>Cele­b­r­a­t­e­C­h­r­i­s­tmas</string>
4

1 に答える 1