简体   繁体   English

数组的Twitter4j ID

[英]Twitter4j IDs to Array

I am attempting to compare two lists. 我正在尝试比较两个列表。 One list contains everyone I am following on twitter, the other is everyone who follows me. 一个列表包含我在Twitter上关注的每个人,另一个列表是关注我的每个人。 I don't know how to do this since .getFollowersIDs and .getFriendsIDs are of type ID. 我不知道该怎么做,因为.getFollowersID和.getFriendsID是ID类型。 I have looked this up, but I can't understand how to compare the results of this type. 我已经查过了,但是我不明白如何比较这种类型的结果。 I tried treating it like they both were arrays, but Eclipse didn't like that.. http://twitter4j.org/javadoc/twitter4j/IDs.html 我尝试将它们都当作数组对待,但是Eclipse不喜欢它。.http: //twitter4j.org/javadoc/twitter4j/IDs.html

The type of the expression must be an array type but it resolved to IDs 表达式的类型必须是数组类型,但必须解析为ID

package com.follow3d.rob;

import java.util.List;
import twitter4j.*;
import twitter4j.conf.*;

public class Follow3d {

    public static void main(String[] args) {

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxx")
                .setOAuthConsumerSecret("xxxxxx")
                .setOAuthAccessToken("xxxxxx")
                .setOAuthAccessTokenSecret("xxxxxx");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        try {
                long ID = twitter.getId();//Personal Twitter ID.
                IDs FOLLOWERS = twitter.getFollowersIDs(-1);//Numeric Array of every user that follows me. 
                IDs FOLLOWING = twitter.getFriendsIDs(-1);//Numeric Array of every user I am following. 
                while (FOLLOWING.hasNext() == true)
                {
                    int counter = 0;
                    if (FOLLOWING[counter] != FOLLOWERS[counter])//ERROR HERE.
                }
            } catch (TwitterException name) {
                System.out.println("You don't have internet connection.");
        }
    }
}

IDs::getIDs() gives you a long[] . IDs::getIDs()给您long[] I think this is what you want. 我想这就是你想要的。

As explained in the documentation , FOLLOWERS and FOLLOWING are of type IDs (not array) and hence, we can't reference any element inside it by index . 文档中所述,FOLLOWERS和FOLLOWING是IDs类型(不是数组),因此,我们不能通过index引用其中的任何元素。

If we need to compare the followers and following user ids then, we need to use getIDs() method of IDs class (ie FOLLOWERS and FOLLOWING objects ) and iterate through them. 如果我们需要比较跟随者和跟随者的用户ID,则需要使用IDs类的getIDs()方法(即FOLLOWERS和FOLLOWING objects )并对其进行迭代。 Also, instead of iterating using while loop (as shown in the example), we need to iterate FOLLOWING array for each element of FOLLOWERS array to see if an id exists or not. 另外,除了使用while循环进行迭代(如示例所示)外,我们还需要为FOLLOWERS数组的每个元素迭代FOLLOWING数组,以查看ID是否存在。

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

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