gpt4 book ai didi

java - 在 Android 中将视频上传到 Facebook 时权限被拒绝

转载 作者:行者123 更新时间:2023-11-30 01:51:02 26 4
gpt4 key购买 nike

我正在编写一个 android 应用程序来上传和分享 facebook 上的视频。我的代码如下:

 public void doShareVideo(View view) {
List<String> permissionNeeds = Arrays.asList("publish_actions","publish_pages");
//this loginManager helps you eliminate adding a LoginButton to your UI
LoginManager manager = LoginManager.getInstance();

manager.logInWithPublishPermissions(this, permissionNeeds);

Uri videoFileUri = Uri.parse("file:///storage/emulated/0/Movies/Untitled.mp4");
ShareVideo video = new ShareVideo.Builder()
.setLocalUrl(videoFileUri)
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(video)
.setContentTitle("Video shared from my android apps")
.build();

ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {

}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException error) {
error.printStackTrace();
}
});
}

但是我在运行时收到错误信息:

10-10 02:57:40.714 19490-19490/? W/System.err: Error preparing share content: Permission denied
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.internal.ShareInternalUtility.invokeOnErrorCallback(ShareInternalUtility.java:529)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.internal.ShareInternalUtility.invokeCallbackWithError(ShareInternalUtility.java:98)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.internal.ShareInternalUtility.invokeCallbackWithException(ShareInternalUtility.java:90)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.ShareApi.shareVideoContent(ShareApi.java:417)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.ShareApi.share(ShareApi.java:186)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.facebook.share.ShareApi.share(ShareApi.java:79)
10-10 02:57:40.714 19490-19490/? W/System.err: at com.anhnn.facebooklogin.ShareLinkActivity.doShareVideo(ShareLinkActivity.java:189)
10-10 02:57:40.714 19490-19490/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
10-10 02:57:40.714 19490-19490/? W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
10-10 02:57:40.714 19490-19490/? W/System.err: at android.view.View$1.onClick(View.java:4015)
10-10 02:57:40.714 19490-19490/? W/System.err: at android.view.View.performClick(View.java:4780)
10-10 02:57:40.714 19490-19490/? W/System.err: at android.view.View$PerformClick.run(View.java:19866)
10-10 02:57:40.715 19490-19490/? W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
10-10 02:57:40.715 19490-19490/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
10-10 02:57:40.715 19490-19490/? W/System.err: at android.os.Looper.loop(Looper.java:135)
10-10 02:57:40.715 19490-19490/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5254)
10-10 02:57:40.715 19490-19490/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
10-10 02:57:40.715 19490-19490/? W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
10-10 02:57:40.715 19490-19490/? W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-10 02:57:40.715 19490-19490/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-10 02:57:40.757 19490-19490/? W/art: Attempt to remove local handle scope entry from IRT, ignoring
10-10 02:57:40.758 19490-19490/? W/AwContents: onDetachedFromWindow called when already detached. Ignoring

我使用 Facebook SDK:com.facebook.android:facebook-android-sdk:4.6.0请帮助我,非常感谢。


对于@Fyodor Volchyok,我已经根据您的建议更改了我的代码,但我没有任何反应。登录Facebook并成功批准权限后,LogCat中无日志信息或无错误显示。我的新代码如下:

public class ShareVideoActivity extends AppCompatActivity {

private static final String LOG_TAG = "ShareVideo";
private CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(this.getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_video);

callbackManager = CallbackManager.Factory.create();
LoginManager loginManager = LoginManager.getInstance();
loginManager.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// it would be nice here to check loginResult.getRecentlyGrantedPermissions() for requested permissions
Log.d(LOG_TAG, "Success " + loginResult.getRecentlyGrantedPermissions().toString());
Uri videoFileUri = Uri.parse("file:///storage/emulated/0/Movies/Untitled.mp4");
ShareVideo video = new ShareVideo.Builder()
.setLocalUrl(videoFileUri)
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(video)
.setContentTitle("Video shared from my android apps")
.build();

ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {

}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException error) {
error.printStackTrace();
}
});
}

@Override
public void onCancel() {
// App code
}

@Override
public void onError(FacebookException exception) {
// App code
}
});
List<String> permissionNeeds = Arrays.asList("publish_actions", "publish_pages");
loginManager.logInWithPublishPermissions(this, permissionNeeds);
}
}

你对我有什么新的建议吗?提前致谢。 (我可以分享图片和链接,但遇到视频问题)

最佳答案

您似乎正在尝试在尚未授予权限的情况下上传视频。尝试以下操作:

  1. 为登录管理器设置回调。
  2. 使用 LoginManager 登录。
  3. (最重要!)等待用户登录。您将通过回调收到通知。
  4. 检查是否授予权限。
  5. 如果是,请上传。

大概的结果是这样的:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());

callbackManager = CallbackManager.Factory.create();

LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback < LoginResult > () {
@Override
public void onSuccess(LoginResult loginResult) {
// it would be nice here to check loginResult.getRecentlyGrantedPermissions() for requested permissions

Uri videoFileUri = Uri.parse("file:///storage/emulated/0/Movies/Untitled.mp4");
ShareVideo video = new ShareVideo.Builder()
.setLocalUrl(videoFileUri)
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(video)
.setContentTitle("Video shared from my android apps")
.build();

ShareApi.share(content, new FacebookCallback < Sharer.Result > () {
@Override
public void onSuccess(Sharer.Result result) {

}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException error) {
error.printStackTrace();
}
});
}

@Override
public void onCancel() {
// App code
}

@Override
public void onError(FacebookException exception) {
// App code
}
});
LoginManager.getInstance().logInWithPublishPermissions(this, permissionNeeds);
}

是的,这段代码可以而且应该改进,但整个想法就在这里。

关于java - 在 Android 中将视频上传到 Facebook 时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33051363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com