2017-04-11 21 views
0

我嘗試從Facebook integration in android如何分享視頻到Facebook的Android上

這裏取一提的是我一步

第一步:嘗試導入Facebook的SDK

repositories { 
     mavenCentral() 
    } 

    dependencies { 
... 
     compile 'com.android.support.constraint:constraint-layout:1.0.2' 
... 
    } 

第二步:設置清單上的代碼,333991926986699爲我的Facebook app_id

<uses-permission android:name="android.permission.INTERNET"/> 

<application 
.... 
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> 

     <provider android:authorities="com.facebook.app.FacebookContentProvider333991926986699" 
      android:name="com.facebook.FacebookContentProvider" 
      android:exported="true" /> 
.... 
    </application> 

,然後在約從官方視頻共享代碼是這樣的:

Uri videoFileUri = ... 
ShareVideo = new ShareVideo.Builder() 
     .setLocalUrl(videoUrl) 
     .build(); 
ShareVideoContent content = new ShareVideoContent.Builder() 
     .setVideo(video) 
     .build(); 

我不知道如何讓它工作。

這是我的視頻link。任何人都可以教我下一步該做什麼?

任何幫助,將不勝感激。

這裏是我嘗試共享代碼:

shareButton=(Button)findViewById(R.id.shareButton); 

     shareButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       Uri videoFileUri=Uri.parse("https://www.youtube.com/watch?v=zeLqNx7dMBM"); 
       ShareVideo shareVideo=new ShareVideo.Builder() 
         .setLocalUrl(videoFileUri) 
         .build(); 
       //There is no use by content 
       ShareVideoContent content=new ShareVideoContent.Builder() 
         .setVideo(shareVideo) 
         .build(); 
      } 
     }); 
+0

嗎? –

+0

我想分享鏈接。 –

+0

好的,我明白了。 「我不知道讓它工作」是什麼意思?它會拋出一個錯誤嗎?也許你應該發佈你的代碼,如何將facebook樣本整合到你的應用程序中 –

回答

1

你想分享一個鏈接,但您使用的是代碼共享的視頻這是您的設備上。

請看看

https://developers.facebook.com/docs/sharing/android

,並嘗試使用代碼共享的鏈接

ShareLinkContent content = new ShareLinkContent.Builder() 
     .setContentUrl(Uri.parse("https://developers.facebook.com")) 
     .build(); 

請考慮,你必須使用Facebook分享按鈕帳戶。請在https://developers.facebook.com/docs/sharing/android

ShareButton shareButton = (ShareButton)findViewById(R.id.fb_share_button); 
shareButton.setShareContent(content); 

底部看到您無法使用標準的Android按鈕,你要上傳影片,或者你想分享的鏈接爲您的視頻

+0

感謝您的回答,但我嘗試使用此代碼作爲按鈕,它不工作,我想念什麼? –

+0

你是什麼意思:它不工作? –

+0

我的意思是它沒有顯示任何佈局或對話框共享視頻 –