⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flickr.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        String resp = HTTP.sendPostRequest(post, "http://www.flickr.com/services/rest/?method=flickr.groups.pools.add", boundary);
        return resp.indexOf("stat=\"ok\"") > -1;
    }

    public void GetBlogList()
    {
        signature = secret_shared + "api_key" + api_key + "auth_token" + auth_token + "methodflickr.blogs.getList";
        api_sig = MD5.getHashString(signature);
        String resp = HTTP.sendGetRequest("http://www.flickr.com/services/rest/?method=flickr.blogs.getList&api_key=" + api_key + "&auth_token=" + auth_token + "&api_sig=" + api_sig);
        String tmpResp = resp.toString();
        int numBlog;
        for(numBlog = 0; tmpResp.indexOf("<blog id") > -1; numBlog++)
            tmpResp = tmpResp.substring(tmpResp.indexOf("<blog id") + 8);

        String BlogsArray[][] = new String[2][numBlog];
        for(int i = 0; resp.indexOf("<blog id") > -1; i++)
        {
            int posTag = resp.indexOf("<blog id");
            int posId = resp.indexOf("id=\"", posTag);
            int posName = resp.indexOf("name=\"", posId);
            String id = resp.substring(posId + 4, resp.indexOf("\"", posId + 4));
            String name = resp.substring(posName + 6, resp.indexOf("\"", posName + 6));
            BlogsArray[0][i] = id;
            BlogsArray[1][i] = name;
            resp = resp.substring(posName + 8);
        }

        Blogs = BlogsArray;
    }

    public void GetSetsList()
    {
        signature = secret_shared + "api_key" + api_key + "auth_token" + auth_token + "methodflickr.photosets.getList";
        api_sig = MD5.getHashString(signature);
        String resp = HTTP.sendGetRequest("http://www.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=" + api_key + "&auth_token=" + auth_token + "&api_sig=" + api_sig);
        String tmpResp = resp.toString();
        int numSets;
        for(numSets = 0; tmpResp.indexOf("<photoset id") > -1; numSets++)
            tmpResp = tmpResp.substring(tmpResp.indexOf("<photoset id") + 12);

        String SetsArray[][] = new String[2][numSets];
        for(int i = 0; resp.indexOf("<photoset id") > -1; i++)
        {
            int posTag = resp.indexOf("<photoset id");
            int posId = resp.indexOf("id=\"", posTag);
            int posName = resp.indexOf("<title>", posId);
            String id = resp.substring(posId + 4, resp.indexOf("\"", posId + 4));
            String name = resp.substring(posName + 7, resp.indexOf("</title>", posName + 7));
            SetsArray[0][i] = id;
            SetsArray[1][i] = name;
            resp = resp.substring(posName + 12);
        }

        Sets = SetsArray;
    }

    public void GetTagsList()
    {
        signature = secret_shared + "api_key" + api_key + "auth_token" + auth_token + "count10methodflickr.tags.getListUserPopular";
        api_sig = MD5.getHashString(signature);
        String resp = HTTP.sendGetRequest("http://www.flickr.com/services/rest/?method=flickr.tags.getListUserPopular&api_key=" + api_key + "&auth_token=" + auth_token + "&api_sig=" + api_sig + "&count=10");
        String tmpResp = resp.toString();
        int numTags;
        for(numTags = 0; tmpResp.indexOf("<tag count") > -1; numTags++)
            tmpResp = tmpResp.substring(tmpResp.indexOf("<tag count") + 10);

        if(resp.indexOf(">j2memap<") > -1)
            numTags--;
        if(resp.indexOf(">cameraphone<") > -1)
            numTags--;
        String TagsArray[] = new String[numTags];
        int i = 0;
        do
        {
            if(resp.indexOf("<tag count") <= -1)
                break;
            int posTag = resp.indexOf("<tag count");
            String tag = resp.substring(resp.indexOf(">", posTag + 10) + 1, resp.indexOf("<", posTag + 10));
            resp = resp.substring(posTag + 10);
            if(!tag.equals(new String("j2memap")) && !tag.equals(new String("cameraphone")))
            {
                TagsArray[i] = tag;
                i++;
            }
        } while(true);
        Tags = TagsArray;
    }

    public void GetGroupsPoolsList()
    {
        signature = secret_shared + "api_key" + api_key + "auth_token" + auth_token + "methodflickr.groups.pools.getGroups";
        api_sig = MD5.getHashString(signature);
        String resp = HTTP.sendGetRequest("http://www.flickr.com/services/rest/?method=flickr.groups.pools.getGroups&api_key=" + api_key + "&auth_token=" + auth_token + "&api_sig=" + api_sig);
        String tmpResp = resp.toString();
        int numGroups;
        for(numGroups = 0; tmpResp.indexOf("<group ") > -1; numGroups++)
            tmpResp = tmpResp.substring(tmpResp.indexOf("<group ") + 7);

        String GroupsArray[][] = new String[2][numGroups];
        for(int i = 0; resp.indexOf("<group ") > -1; i++)
        {
            int posGroup = resp.indexOf("<group ");
            int posId = resp.indexOf("nsid=\"", posGroup);
            int posName = resp.indexOf("name=\"", posId);
            String id = resp.substring(posId + 6, resp.indexOf("\"", posId + 6));
            String name = resp.substring(posName + 6, resp.indexOf("\"", posName + 7));
            GroupsArray[0][i] = id;
            GroupsArray[1][i] = name;
            resp = resp.substring(posName + 1);
        }

        GroupsPools = GroupsArray;
    }

    public String GetUrl(String photoId)
    {
        signature = secret_shared + "api_key" + api_key + "auth_token" + auth_token + "methodflickr.photos.getInfo" + "photo_id" + photoId;
        api_sig = MD5.getHashString(signature);
        String boundary = GenerateBoundary();
        String post = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"api_key\"\r\n" + "\r\n" + api_key + "\r\n" + "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"auth_token\"\r\n" + "\r\n" + auth_token + "\r\n" + "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"photo_id\"\r\n" + "\r\n" + photoId + "\r\n" + "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"api_sig\"\r\n" + "\r\n" + api_sig + "\r\n" + "--" + boundary + "--\r\n";
        String resp = HTTP.sendPostRequest(post, "http://www.flickr.com/services/rest/?method=flickr.photos.getInfo", boundary);
        String tmpResp = resp.toString();
        String secret = GetField(tmpResp, "photo", "secret");
        String server = GetField(tmpResp, "photo", "server");
        String farm = GetField(tmpResp, "photo", "farm");
        System.out.println(" Received: secret:" + secret + " server:" + server + " farm:" + farm);
        return "http://farm" + farm + ".static.flickr.com/" + server + "/" + photoId + "_" + secret + "_m.jpg";
    }

    private String GetParameter(String str, String param)
    {
        String startTag = "<" + param + ">";
        String endTag = "</" + param + ">";
        if(str.indexOf(startTag) > -1 && str.indexOf(endTag) > -1)
        {
            if(str.indexOf(startTag) + startTag.length() < str.indexOf(endTag))
                return str.substring(str.indexOf(startTag) + startTag.length(), str.indexOf(endTag));
            else
                return "";
        } else
        {
            return "";
        }
    }

    private String GetField(String str, String param, String field)
    {
        String startTag = "<" + param;
        String endTag = "/>";
        if(str.indexOf(startTag) > -1 && str.indexOf(endTag) > -1 && str.indexOf(startTag) + startTag.length() < str.indexOf(endTag))
        {
            String theString = str.substring(str.indexOf(startTag) + startTag.length(), str.indexOf(endTag));
            startTag = field + "=\"";
            endTag = "\"";
            int start = theString.indexOf(startTag);
            if(start > -1 && theString.indexOf(endTag, start) > -1 && theString.indexOf(startTag) + startTag.length() < theString.indexOf(endTag, start + startTag.length()))
                return theString.substring(theString.indexOf(startTag) + startTag.length(), theString.indexOf(endTag, start + startTag.length()));
        }
        return "";
    }

    private String GenerateBoundary()
    {
        String boundary = "";
        Random random = new Random();
        Date date = new Date();
        random.setSeed(date.getTime());
        boundary = boundary + Integer.toHexString(random.nextInt());
        boundary = boundary + Integer.toHexString(random.nextInt());
        return "---------------------------" + boundary.substring(4);
    }

    private String api_key;
    private String auth_token;
    private String secret_shared;
    private String api_sig;
    private String method;
    private String signature;
    private String autentication_url;
    private String mini_token;
    private String querystring;
    public String Blogs[][];
    public String Tags[];
    public String Sets[][];
    public String GroupsPools[][];
    private int lastCode;
    private String lastErrorMsg;
    private Settings settings;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -