输出java:计算每个朋友的重量

时间:2017-07-07 19:44:20

标签: java facebook api facebook-graph-api

我的java类的输出如下:

created time Thu Jun 15 03:52:53 CEST 2017 
Id Poste: fb.com/1562752627337463_1951227231823332 
le poid de l'interaction Wint 1.0 
Fifi Daly Omm Omar 
Toka Ep Bouzidi 
=================================== 
created time Wed Jun 14 21:14:14 CEST 2017 
Id Poste: fb.com/1562752627337463_1951069731839082 
le poid de l'interaction Wint 0.9 
Sami Dali 
Toka Ep Bouzidi 
Àmine OuLéd Ahméd 
Faiza Ouled Ahmed 
Rania Trigui 
Hàifà Gassoumi 
Awatef Cherif 
Dali Montassar 
Souad Brahmi 
Nabiha Ben Aissa 
Deli Maha 
=================================== 
created time Wed Jun 14 19:39:27 CEST 2017 
Id Poste: fb.com/149760905397346_444326185940815 
le poid de l'interaction Wint 0.9 

=================================== 
created time Wed Jun 14 01:26:57 CEST 2017 
Id Poste: fb.com/1562752627337463_1950398421906213 
le poid de l'interaction Wint 0.7 
Nesrine Jalleli 
Esmeralda Sagittaire 
Aymen J'rb 
=================================== 

我还有另一个课程,向我展示我所有朋友的名字:输出如下:

**Sami Dali 
Toka Ep Bouzidi 
Àmine OuLéd Ahméd 
Faiza Ouled Ahmed 
Rania Trigui 
Hàifà Gassoumi 
Awatef Cherif 
Dali Montassar 
Souad Brahmi 
Nabiha Ben Aissa 
Deli Maha 
Nesrine Jalleli 
Esmeralda Sagittaire 
Aymen J'rb 
etc..** 

我的问题是如何计算每个朋友的权重总和 这是我的java代码:

import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.Post;
import java.io.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Optional;

public class main {

    public static void main(String[] args) throws IOException {
       String accessToken ="EAACEdEose0cBANEXpFEXQZALRTI8k84B2po0w";
       FacebookClient fbclient = new DefaultFacebookClient(accessToken);
       Connection<Post> result = fbclient.fetchConnection("me/feed",Post.class );
       int counter = 0;
  for(List<Post> page : result)
  {
        for(Post aPost : page)
            {    
                 Calendar c = Calendar.getInstance();
                 Calendar a = Calendar.getInstance();
                 a.add(Calendar.YEAR, -10);
                 Date Fin = a.getTime();
                 Date db = c.getTime();
                 Date time = aPost.getCreatedTime();
                 double CONST_DURATION_OF_DAY = 1000l * 60 * 60 * 24;
                 double diff = Math.abs(db.getTime() - time.getTime());
                 double numberOfDay = Math.round((diff/CONST_DURATION_OF_DAY) * 
                  100) / 100;
                 double numberofyear = (double) Math.round((numberOfDay/356) * 100) 
                  / 100;
                double dbwint = (100-(numberofyear*10))/100 ;
                double Wint  = (double) Math.round( dbwint * 100) / 100;

      if(!time.before(Fin))
       {

System.out.println("created time     "+time+"\r\n");
System.out.println("Id Poste: fb.com/"+aPost.getId()+"\r\n");
System.out.println("le poid de l'interaction Wint  "+Wint+"\r\n");
Optional.ofNullable(aPost .flatMap(post -> Optional.ofNullable(post.getLikes()))
    .flatMap(likes -> Optional.ofNullable(likes.getData()))
    .ifPresent(likes -> likes.stream()
    .map(likeItem -> Optional.ofNullable(likeItem.getName()))
    .forEach(optName -> optName.ifPresent(name ->
     System.out.println(name + "\r\n"))));

System.out.println("==================================="+"\r\n");

counter++;

       }
 else {System.out.println("date hors période"+"\r\n");}

}
  System.out.println("number of results"+counter);

}
  }
   }
    }

0 个答案:

没有答案