我正在实施使用YouTube API v3的Android应用程序
即使更改Google云API中的项目名称或将Android密钥更改为浏览器密钥,我也始终收到“未配置访问”
我正在搜索用户订阅的订阅
这是我的所有代码
public class Youtube extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener
{
private YouTubePlayer YPlayer;
private static final int RECOVERY_DIALOG_REQUEST = 1;
private static YouTube youtube;
GoogleAccountCredential credential;
GoogleCredential CREDENTIAL = new GoogleCredential();
com.google.api.services.youtube.YouTube service;
final HttpTransport transport = AndroidHttp.newCompatibleTransport();
final JsonFactory jsonFactory = new GsonFactory();
final String CLIENT_ID = "client key";
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String test = mPreferences.getString("USER_ACCOUNT_AUTH_PREF", null);
AccountManager.get(getApplicationContext()).invalidateAuthToken("com.google", test);
final SharedPreferences.Editor editor = mPreferences.edit();
AccountManager.get(getApplicationContext()).getAuthTokenByFeatures(
"com.google", "oauth2:https://gdata.youtube.com", null,this, null, null, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bundle = future.getResult();
String acc_name = bundle
.getString(AccountManager.KEY_ACCOUNT_NAME);
String auth_token = bundle
.getString(AccountManager.KEY_AUTHTOKEN);
System.out.println("name: " + acc_name + "; token: "
+ auth_token);
editor.putString("USER_ACCOUNT_PREF", acc_name);
editor.putString("USER_ACCOUNT_AUTH_PREF", auth_token);
} catch (Exception e) {
System.out.println( e.getClass().getSimpleName() + ": "
+ e.getMessage());
}
}
}, null);
editor.commit();
String test2 = mPreferences.getString(
"USER_ACCOUNT_AUTH_PREF", null);
CREDENTIAL.setAccessToken(test2);
credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(),
Arrays.asList(Auth.SCOPES) );
credential.setSelectedAccountName(mPreferences.getString("USER_ACCOUNT_PREF", null));
youtube = new YouTube.Builder(
transport, jsonFactory, credential).setApplicationName(
getPackageName()).setHttpRequestInitializer(CREDENTIAL)
.setGoogleClientRequestInitializer(new YouTubeRequestInitializer(CLIENT_ID))
.build();
RetreiveFeedTask task= new RetreiveFeedTask();
task.execute();
}
class RetreiveFeedTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
try {
try {
YouTube.Subscriptions.List subscriber = youtube.subscriptions().list("snippet");
subscriber.setMine(true);
subscriber.setKey(api key);
subscriber.execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("subscribe exception");
}
}
catch(Exception e){
System.out.println("exception");}
return null;
}}
}
所以现在我该怎样做才能获得用户订阅的订阅?