6

I build web and mobile app and they are synchronized. So, after I login and authorize google account to get access token, refresh token, expires to upload video on youtube and store in database. And on mobile, I get access token, refresh token, expires ria api that I write and mobile app use access token to upload video without login google account to get access token. If access token is expired, I will use refresh token to re-generate access token. Now, I have done in iOS, but in Android I still can't do it.

user1916184
  • 135
  • 2
  • 14
  • Is not [this](https://developers.google.com/youtube/v3/code_samples/java#upload_a_video) exactly what you are searching? –  Jan 26 '16 at 08:06
  • @user1916184 What part of this can you not do ? Is the issue that you cannot regenerate the access token ? Please provide code samples and errors showing your work – OYRM Jan 28 '16 at 16:49
  • same problem ? if you found any solution, can u share your code with me please ? – podgradle Feb 25 '18 at 17:12

1 Answers1

1
public class UploadService extends AsyncTask<Void,Void,String>
{
    String base64_video="";
    String tokenValue="";
     ProgressDialog uploadDialog = new ProgressDialog(FinalStandardActivity.this);


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        base64_video=convertToBase64(_newVideoPath);

        uploadDialog.setMessage("Uploading...");
        uploadDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        uploadDialog.setCancelable(false);
        uploadDialog.show();

    }

    @Override
    protected String doInBackground(Void... params) {

        File file=new File(_newVideoPath);

        loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE);
        tokenValue=loginPreferences.getString("googleToken","");

        if(tokenValue.contentEquals(""))
        {

        }
        else
        {
           JSONObject snippet=new JSONObject();

            //VideoSnippet snippet = new VideoSnippet();
            VideoStatus status = new VideoStatus();




            try
            {

                snippet.put("categoryId", "22");
                snippet.put("description", "Description of uploaded video.");
                snippet.put("title", "Test video upload");
                status.set("privacyStatus", "private");


            }
            catch (Exception e)
            {
                e.printStackTrace();
            }



            // .addFormDataPart("snippet","snippet",RequestBody.create(MediaType.parse("application/json; charset=utf-8"),snippet.toString()))



            OkHttpClient client = new OkHttpClient();
            RequestBody formBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("snippet","snippet",
                            RequestBody.create(MediaType.parse("application/json; charset=utf-8"),snippet.toString()))
                    .addFormDataPart("videoFile", file.getName(),
                            RequestBody.create(MediaType.parse("video/*"), file))
                    .build();
            //   let metadata = "{'snippet':{'title' : 'title', 'description': 'description'}}".data(using: .utf8, allowLossyConversion: false)!

            //MediaType.parse("application/json; charset=utf-8")



            //UPLOAD_URL=UPLOAD_URL+"?part="+snippet.toString();

            Request request = new Request.Builder()
                    .addHeader("Authorization","Bearer "+tokenValue)
                    .addHeader("Content-Type", "application/json")
                    .addHeader("cache-control", "no-cache")
                    .url(UPLOAD_URL)
                    .post(formBody)
                    .build();

            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e)
                {
                    Log.e(TAG, e.toString());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException
                {
                    Log.e(TAG,response.body().toString());
                    uploadDialog.dismiss();
                }
            });

        }
        return null;
    }
}
  • I need help. What library did u use for this ? I need token and want to upload video with this token to youtube please help me ismailtsn92@gmail.com – podgradle Feb 26 '18 at 21:04