void postScreenShot(long albumId)
    {
        StartCoroutine(getScreenShotFromScreen(delegate(Texture2D tex) {
            Dictionary <string, object> getUploadServParams = new Dictionary <string, object>();
            getUploadServParams["album_id"] = (long)albumId;
            vkc.api("photos.getUploadServer", getUploadServParams, delegate(object arg1, Callback arg2){
                Debug2.LogDebug("im at  postScreenShot getWallUploadServer=====\n" + Json.Serialize(arg1));
                Dictionary <string, object> resultDict = arg1 as Dictionary <string, object>;
                if (!resultDict.ContainsKey("response"))
                {
                    Debug2.LogError("vk api error \n" + Json.Serialize(arg1));
                    return;
                }
                Dictionary <string, object> response = resultDict["response"] as Dictionary <string, object>;
                string upload_url = (string)response["upload_url"];
                WWWForm form      = new WWWForm();

                form.AddBinaryData("photo", tex.EncodeToPNG(), "PHOTO_NAME.png", "image/png");

                StartCoroutine(CallbackOnWWWResponse(upload_url, form,
                                                     delegate(string postResult){
                    Debug2.LogDebug("post success \n" + postResult);
                    Dictionary <string, object> postResultDict = Json.Deserialize(postResult) as Dictionary <string, object>;

                    Dictionary <string, object> parameters = new Dictionary <string, object>();
                    parameters["album_id"]    = albumId;
                    parameters["server"]      = postResultDict["server"];
                    parameters["photos_list"] = postResultDict["photos_list"];
                    parameters["hash"]        = postResultDict["hash"];
                    parameters["caption"]     = "test upload to vk server";

                    vkc.api("photos.save", parameters, delegate(object psarg1, Callback psarg2) {
                        Debug2.LogDebug("im at  postScreenShot getWallUploadServer=====\n" + Json.Serialize(psarg1));
                        Dictionary <string, object> psresultDict = psarg1 as Dictionary <string, object>;
                        if (!psresultDict.ContainsKey("response"))
                        {
                            Debug2.LogError("vk api error \n" + Json.Serialize(psarg1));
                        }
                        else
                        {
                            Debug2.LogDebug("photos post success \n" + Json.Serialize(psarg1));
                            long photoId = (long)((psresultDict["response"] as List <object>)[0] as Dictionary <string, object>)["id"];

                            vkc.windowConfirm("ваша картинка успешно сохранена\\n" +
                                              "в альбоме \"" + albumName + "\"\\n" +
                                              "хотите добавить ее на стену?", delegate(object confirmObject, Callback confirmCallback) {
                                bool result = (bool)confirmObject;
                                Debug2.LogDebug("confirmation result = " + result);
                                if (result)
                                {
                                    Dictionary <string, object> wallProps = new Dictionary <string, object>();
                                    wallProps["owner_id"]    = vkc.inputData["viewer_id"];
                                    wallProps["message"]     = "тестовая запись на стену";
                                    wallProps["attachments"] = "photo" + vkc.inputData["viewer_id"] + "_" + photoId;
                                    vkc.api("wall.post", wallProps, delegate(object wallPostObj, Callback wallPostCallback) {
                                        if (!(wallPostObj as Dictionary <string, object>).ContainsKey("response"))
                                        {
                                            Debug2.LogError("problem with wall.post upload " + Json.Serialize(wallPostObj));
                                        }
                                    });
                                }
                            });
                        }
                    });
                },
                                                     delegate(string postError){
                    Debug2.LogError("problem with post photo\n" + postError);
                }
                                                     ));
            });
        }));
    }
コード例 #2
0
    void postScreenShot(Texture2D tex, string wallText, long albumId)
    {
        Dictionary <string, object> getUploadServParams = new Dictionary <string, object>();

        getUploadServParams["album_id"] = (long)albumId;
        vkc.api("photos.getUploadServer", getUploadServParams, delegate(object arg1, Callback arg2){
            Debug2.LogDebug("im at  postScreenShot getWallUploadServer=====\n" + Json.Serialize(arg1));
            Dictionary <string, object> resultDict = arg1 as Dictionary <string, object>;
            if (!resultDict.ContainsKey("response"))
            {
                Debug2.LogError("vk api error \n" + Json.Serialize(arg1));
                return;
            }
            Dictionary <string, object> response = resultDict["response"] as Dictionary <string, object>;
            string upload_url = (string)response["upload_url"];

            vkc.uploadTexture(tex, upload_url, "colorus",
                              delegate(string postResult){
                Debug2.LogDebug("post success \n" + postResult);
                Dictionary <string, object> postResultDict = Json.Deserialize(postResult) as Dictionary <string, object>;

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters["album_id"]    = albumId;
                parameters["server"]      = postResultDict["server"];
                parameters["photos_list"] = postResultDict["photos_list"];
                parameters["hash"]        = postResultDict["hash"];
                parameters["caption"]     = "test upload to vk server";

                vkc.api("photos.save", parameters, delegate(object psarg1, Callback psarg2) {
                    Debug2.LogDebug("im at  postScreenShot getWallUploadServer=====\n" + Json.Serialize(psarg1));
                    Dictionary <string, object> psresultDict = psarg1 as Dictionary <string, object>;
                    if (!psresultDict.ContainsKey("response"))
                    {
                        Debug2.LogError("vk api error \n" + Json.Serialize(psarg1));
                    }
                    else
                    {
                        Debug2.LogDebug("photos post success \n" + Json.Serialize(psarg1));
                        long photoId = (long)((psresultDict["response"] as List <object>)[0] as Dictionary <string, object>)["id"];

                        vkc.windowConfirm("ваша картинка успешно сохранена\\n" +
                                          "в альбоме \"" + albumName + "\"\\n" +
                                          "хотите добавить ее на стену?", delegate(object confirmObject, Callback confirmCallback) {
                            bool result = (bool)confirmObject;
                            Debug2.LogDebug("confirmation result = " + result);
                            if (result)
                            {
                                WebContext.instance.hideApplication();
                                Dictionary <string, object> wallProps = new Dictionary <string, object>();
                                wallProps["owner_id"]    = vkc.inputData["viewer_id"];
                                wallProps["message"]     = wallText;
                                wallProps["attachments"] = "photo" + vkc.inputData["viewer_id"] + "_" + photoId;
                                vkc.api("wall.post", wallProps, delegate(object wallPostObj, Callback wallPostCallback) {
                                    if (!(wallPostObj as Dictionary <string, object>).ContainsKey("response"))
                                    {
                                        Debug2.LogError("problem with wall.post upload " + Json.Serialize(wallPostObj));
                                    }
                                    WebContext.instance.showApplication();
                                });
                            }
                        });
                    }
                });
            },
                              delegate(string postError){
                Debug2.LogError("problem with post photo\n" + postError);
            }
                              );
        });
    }