我要因为这个错误而发疯了。据我所知,我正确地遵守了指示。我的范围是YOUTUBE_FORCE_SSL。在绝望中,我试图添加所有谷歌加Scopes没有运气。在设备、模拟器和中,仍然会出现相同的错误。我试图评论的视频是公开的。我有一个Google+配置文件,当我试图发表评论时,它会被注册。
这是完全错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.commentThread",
"location" : "Authorization",
"locationType" : "header",
"message" : "The callers YouTube account is not connected to Google+.",
"reason" : "ineligibleAccount"
} ],
"message" : "The callers YouTube account is not connected to Google+."
}
这是我的代码:
try {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet");
CommentThread commentThread = new CommentThread();
CommentThreadSnippet snippet = new CommentThreadSnippet();
Comment topLevelComment = new Comment();
CommentSnippet commentSnippet = new CommentSnippet();
commentSnippet.set("textOriginal", textComment);
commentSnippet.set("channelId", channelId);
commentSnippet.set("videoId", ytId);
topLevelComment.setSnippet(commentSnippet);
snippet.setTopLevelComment(topLevelComment);
commentThread.setSnippet(snippet);
YouTube.CommentThreads.Insert commentThreadsInsertRequest = mService.commentThreads().insert(parameters.get("part"), commentThread);
CommentThread response = commentThreadsInsertRequest.execute();
Log.i("COMMENT:", response.toString());
}
添加来自Api的屏幕快照:
您能让CommentThreads:插入与API一起工作吗?如果是这样的话,是怎么做的?
我看到了一个类似问题的答案,这里,他们不能解决这个问题。
任何帮助都是非常感谢的。
编辑1
经过进一步的测试。我有一个旧账户,一切都很好。我试着看看哪些设置可能不同,到目前为止没有运气。
如果我切换到一个YouTube品牌帐户,这也是可行的。
问题仍然存在,它并不适用于所有的Google帐户,即使它们也是Google+帐户。该错误似乎意味着请求不是从Google+帐户发出的。如果谷歌能澄清确切的原因,那就太好了。
还可以在请求帐户所有者的许可后,以编程的方式使帐户有资格进行评论吗?怎么做?
编辑2
根据此页,错误的原因是:
用于授权API请求的YouTube帐户必须与用户的Google帐户合并,以插入注释或注释线程。
如何在应用程序中做到这一点?
编辑3
我想答案可以找到这里。如果没有YouTube频道,您就不能发表评论。
问题是,你不能评论,除非你有一个私人的YouTube频道或登录到您的品牌帐户。使用Google在说明中给出的登录模型不允许使用品牌帐户登录,它们在帐户选择器中不可见。
其结果是,您可以使用具有YouTube品牌帐户的帐户登录,但您将无法使用该帐户进行评论,因为您无法选择一个品牌帐户,除非您要求用户也创建一个私有频道,否则无法解决这个问题。错误消息应该如下所示:
调用方YouTube帐户不是YouTube信道帐户。
发布于 2018-06-12 22:14:31
由于您不能在没有私有YouTube通道的情况下发布评论(请参阅上面的编辑),解决方案将如下所示。如果你能找到一个更好的,请提交!
1)捕捉错误。向警报发出指示。
2)使用以下网址启动Webview:完成
3)监视Webview并确定URL何时更改为以下内容:完成。URL指示已经创建了一个通道。
4)关闭Webview并重新发送授权的API请求。
上面的URL是这里,但是要捕获的错误代码与页面上的错误代码不一样。你应该用“理由”:"ineligibleAccount“来抓一个403。
更新2018年6月29日
我今天回到这个问题上,让它以一种可以接受的方式运作。见下文的实施情况:
1.在没有YouTube频道的用户发布评论后捕获错误403
if(mLastError.getMessage().contains("403") && mLastError.getMessage().contains("ineligibleAccount")) {
// Show Alert with instruction
showAlertCreate("Please Create a YouTube Channel!", "You need a personal YouTube Channel linked to your Google Account before you can comment. Don't worry, it's easy to create one!\n\n1) Tap on CREATE below and wait for page to load.\n\n2) Login if needed.\n\n3) Tap CREATE CHANNEL and wait until comment is posted.");
}
警报代码:
public void showAlertCreate(String title, String description) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(this);
}
builder.setTitle(title)
.setMessage(description)
.setPositiveButton(R.string.yes_create, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Start Youtube WebView to create Channel
Intent intent = new Intent(mContext, WebViewActivity.class);
startActivityForResult(intent, 777);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
2.当用户点击在警报中创建时,打开这个WebView
请注意下面的代码,以便在上面发出警告时启动意图:
// Start Youtube WebView to create Channel
Intent intent = new Intent(mContext, WebViewActivity.class);
startActivityForResult(intent, 777);
用于WebView的XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WebViewActivity">
<WebView
android:id="@+id/create_channel"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
WebView代码:
public class WebViewActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
WebView createChannel = findViewById(R.id.create_channel);
createChannel.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
if (url!=null && url.contains("https://m.youtube.com/channel_creation_done")) {
view.setVisibility(View.INVISIBLE);
//Log.i("URLWEB", url);
Intent intent = new Intent();
intent.putExtra("created", "yes");
setResult(RESULT_OK, intent);
finish();
}
}
});
createChannel.loadUrl("https://m.youtube.com/create_channel?chromeless=1&next=/channel_creation_done");
}
}
3.当用户完成在活动中创建通道步骤时捕获
在onActivityResult()中包括如下内容:
if (requestCode == 777) {
if(resultCode == RESULT_OK) {
// Receive intent from WebView, if new Channel, repost comment/reply
String created = data.getStringExtra("created");
if(created.equals("yes")) {
// Posting the comment again
getResultsFromApi();
}
}
}
不是最干净的解决方案,但有效。
发布于 2021-11-29 05:21:38
如果您已经创建了一个新的帐户,如果您没有评论任何youtube视频,那么它会引发错误:“调用者YouTube帐户没有连接到Google+。”
解决方案:至少在使用新帐户的youtube视频中手动注释,然后尝试API。它运行得很顺利。
https://stackoverflow.com/questions/50828577
复制相似问题