java - Permission denied when uploading a video to Facebook in Android -
i'm writing android app upload , share video on facebook. code below:
public void dosharevideo(view view) { list<string> permissionneeds = arrays.aslist("publish_actions","publish_pages"); //this loginmanager helps eliminate adding loginbutton 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 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(); } }); }
but error message when running:
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: @ com.facebook.share.internal.shareinternalutility.invokeonerrorcallback(shareinternalutility.java:529) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.facebook.share.internal.shareinternalutility.invokecallbackwitherror(shareinternalutility.java:98) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.facebook.share.internal.shareinternalutility.invokecallbackwithexception(shareinternalutility.java:90) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.facebook.share.shareapi.sharevideocontent(shareapi.java:417) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.facebook.share.shareapi.share(shareapi.java:186) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.facebook.share.shareapi.share(shareapi.java:79) 10-10 02:57:40.714 19490-19490/? w/system.err: @ com.anhnn.facebooklogin.sharelinkactivity.dosharevideo(sharelinkactivity.java:189) 10-10 02:57:40.714 19490-19490/? w/system.err: @ java.lang.reflect.method.invoke(native method) 10-10 02:57:40.714 19490-19490/? w/system.err: @ java.lang.reflect.method.invoke(method.java:372) 10-10 02:57:40.714 19490-19490/? w/system.err: @ android.view.view$1.onclick(view.java:4015) 10-10 02:57:40.714 19490-19490/? w/system.err: @ android.view.view.performclick(view.java:4780) 10-10 02:57:40.714 19490-19490/? w/system.err: @ android.view.view$performclick.run(view.java:19866) 10-10 02:57:40.715 19490-19490/? w/system.err: @ android.os.handler.handlecallback(handler.java:739) 10-10 02:57:40.715 19490-19490/? w/system.err: @ android.os.handler.dispatchmessage(handler.java:95) 10-10 02:57:40.715 19490-19490/? w/system.err: @ android.os.looper.loop(looper.java:135) 10-10 02:57:40.715 19490-19490/? w/system.err: @ android.app.activitythread.main(activitythread.java:5254) 10-10 02:57:40.715 19490-19490/? w/system.err: @ java.lang.reflect.method.invoke(native method) 10-10 02:57:40.715 19490-19490/? w/system.err: @ java.lang.reflect.method.invoke(method.java:372) 10-10 02:57:40.715 19490-19490/? w/system.err: @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) 10-10 02:57:40.715 19490-19490/? w/system.err: @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) 10-10 02:57:40.757 19490-19490/? w/art: attempt remove local handle scope entry irt, ignoring 10-10 02:57:40.758 19490-19490/? w/awcontents: ondetachedfromwindow called when detached. ignoring
i use facebook sdk: com.facebook.android:facebook-android-sdk:4.6.0 please me , thank much.
to @fyodor volchyok, changed code suggestion, nothing happens me. no log information or no error showed in logcat after log-in facebook , approving permissions successfully. new code below:
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) { // nice here check loginresult.getrecentlygrantedpermissions() 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 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); } }
do have new suggestion me? in advance. (i can share image , link encountering problem video)
it seems you're trying upload video when permissions hasn't been granted yet. try following:
- set callbacks loginmanager.
- log in loginmanager.
- (most important!) wait user log in. notified via callbacks.
- check whether permissions granted.
- if so, upload.
approximate result this:
@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) { // nice here check loginresult.getrecentlygrantedpermissions() 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 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); }
and yes, code , should improved, whole idea here.
Comments
Post a Comment