0

私はFacebookのグラフAPIに取り組んでいます。そして、私のアプリを使用しているユーザーのIDをすでに取得しています。ユーザーのIDとやりたいことを表示できます。テーブルビューの各セルに、良いユーザーのFBProfilePictureViewが表示されます。

  [[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {}

     NSString* fql =
     @"SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

     [FBRequestConnection startWithGraphPath:@"/fql"
                                  parameters:@{ @"q" : fql}
                                  HTTPMethod:@"GET"
                           completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                               FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
                               [fql.parameters setObject:@"SELECT uid,name,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"];

                               [fql startWithCompletionHandler:^(FBRequestConnection *connection,
                                                                 id result,
                                                                 NSError *error) {
                                   if (result) {


                                       NSArray *arrayRsult = [result objectForKey:@"data"];

                                       NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:@"uid"];
                                       NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:@"name"];

                                       recentFriends = [[NSMutableArray alloc] init];
                                       idFriends = [[NSMutableArray alloc] init];










                                       for (NSDictionary *c  in ids)
                                       {
                                           [idFriends addObject:c];



                                       }


                                        arrayLength = [recentFriends count];




                                       NSLog(@"ids are : %@ ",idFriends);

                                       NSLog(@"there are %i", arrayLength);

まず、このコードを使用して各セルに Facebook のプロフィール写真を表示します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

FBProfilePictureView *prof = [[FBProfilePictureView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];

[[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {
         prof.profileID = [user objectForKey:@"id"];
     }
 }];

            [cell addSubview:prof];

}

カスタムセルとカスタムセルのペン先は使用しません。このテーブルの配列を作成する方法がわかりません。私はこのコードを試しました cell.imageView.image = [idFriends objectAtIndex:indexPath.row]; (idFriends は .h ファイルで __block NSMutableArray として宣言されています) 助けてくれてありがとう!

4

2 に答える 2

3

はい、ユーザーのプロフィール写真を に表示UITableViewCellできます。Cell のデフォルトの ImageView を使用できます。Facebook ID次のように、ユーザーのプロフィール写真を取得できます。

プロファイル用の小さい/サム イメージを取得するには

http://graph.facebook.com/<Friends Facebook ID>/picture?type=small

次のパラメーターをtype、normal、large、square で試すこともできます

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://graph.facebook.com/517267866/picture?type=small"]];
UIImage *profilePic = [UIImage imageWithData:imageData];

指定されたコードは、URL から画像を取得し、それUIImageをあなたのUIImageView

詳細については、こちらのドキュメントをお読みください。

cell.imageView.image = profilePic;
于 2013-05-08T04:21:51.333 に答える
0

実際に「http://graph.facebook.com/ /picture?type=small」 を使用して、ユーザーまたはその友人のプロフィール画像を取得するのは遅いです。

FBProfilePictureView オブジェクトをビューに追加し、その profileID プロパティでユーザーの Facebook ID を割り当てるための、より優れた高速な方法です。

例: FBProfilePictureView *friendsPic;

friendsPic.profileID = @"1379925668972042";

于 2014-12-29T10:39:23.827 に答える