问题描述
我正在将视频上传到 youtube,默认情况下会上传给已登录 google 帐户的用户.
i am uploading video to youtube which by default uploads to user who have login in google account.
但我想设置所有视频都应该使用我的静态 gmailID 和密码上传
But i want to set that all video should upload using my static gmailID and password
是否可以直接使用静态邮箱和密码登录谷歌账户?
Is it possible to Login in google account directly using static emailid and password ?
或任何其他好的 api 或示例在 youtube 上上传视频.
Or any other good api or example to upload video in youtube.
提前谢谢....
推荐答案
我已经成功上传了youtube视频.
I have uploaded youtube video successfully.
- 录制视频并上传
- 来自 SD 卡的视频
通过使用 这个
步骤:
1) 从此 链接<下载 ytd-android-0.2.tar.gz/a>
1) Download ytd-android-0.2.tar.gz from this link
2) 导入为 android 项目.
2) Import as an android project.
3) 将文件:GlsAuthorizer.java 替换为 ClientLoginAuthorizer.java
3) Replace file: GlsAuthorizer.java with ClientLoginAuthorizer.java
4) 在ClientLoginAuthorizer.java
5) 向 www.appspot.com
6) 设置string.xml文件
7) 运行项目.....给你.
7) Run project..... here you go.
ClientLoginAuthorizer.java 的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
/**
* Created by IntelliJ IDEA. User: jarekw Date: Nov 18, 2010 Time: 11:21:36 PM
* To change this template use File | Settings | File Templates.
*/
public class ClientLoginAuthorizer implements Authorizer {
public static final String YOUTUBE_AUTH_TOKEN_TYPE = "youtube";
private static final String AUTH_URL = "https://www.google.com/accounts/ClientLogin";
private Context ctx;
private static final String LOG_TAG = ClientLoginAuthorizer.class
.getSimpleName();
public ClientLoginAuthorizer(Context context) {
this.ctx = context;
}
@Override
public void fetchAccounts(AuthorizationListener<String[]> listener) {
// not used
}
@Override
public void addAccount(Activity activity,
AuthorizationListener<String> listener) {
// not used
}
@Override
public void fetchAuthToken(String accountName, Activity activity,
AuthorizationListener<String> listener) {
Log.d(LOG_TAG, "Getting " + YOUTUBE_AUTH_TOKEN_TYPE + " authToken for "
+ accountName);
try {
String token = getCLAuthToken(accountName);
listener.onSuccess(token);
} catch (Exception e) {
listener.onError(e);
}
}
@Override
public String getAuthToken(String accountName) {
try {
String token = getCLAuthToken(accountName);
return token;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public String getCLAuthToken(String accountName) throws IOException {
HttpURLConnection urlConnection = getGDataUrlConnection(AUTH_URL);
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
String template = "Email=%s&Passwd=%s&service=%s&source=%s";
String userName = "USERNAME"; // TODO
String password = "PASSWORD"; // TODO
String service = YOUTUBE_AUTH_TOKEN_TYPE;
String source = ctx.getString(R.string.client_id);
String loginData = String.format(template, encode(userName),
encode(password), service, source);
OutputStreamWriter outStreamWriter = new OutputStreamWriter(
urlConnection.getOutputStream());
outStreamWriter.write(loginData);
outStreamWriter.close();
int responseCode = urlConnection.getResponseCode();
if (responseCode != 200) {
Log.d(LOG_TAG, "Got an error response : " + responseCode + " "
+ urlConnection.getResponseMessage());
throw new IOException(urlConnection.getResponseMessage());
} else {
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("Auth=")) {
String split[] = line.split("=");
String token = split[1];
Log.d(LOG_TAG, "Auth Token : " + token);
return token;
}
}
}
throw new IOException("Could not read response");
}
private String encode(String string) throws UnsupportedEncodingException {
return URLEncoder.encode(string, "UTF-8");
}
private HttpURLConnection getGDataUrlConnection(String urlString)
throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
return connection;
}
@Override
public String getFreshAuthToken(String accountName, String authToken) {
return getAuthToken(accountName);
}
public static class ClientLoginAuthorizerFactory implements
AuthorizerFactory {
public Authorizer getAuthorizer(Context context, String authTokenType) {
return new ClientLoginAuthorizer(context);
}
}
}
这篇关于android youtube使用静态用户名和密码上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!