2016-04-12 5 views
-1

私はface64でbase64でエンコードされた画像を投稿したいと思います。以下は私のコードですfacebook apiのpublish_action権限の使用方法は?

function postImageToFacebook(authToken, filename, mimeType, imageData, message) { 
     // this is the multipart/form-data boundary we'll use 
     var boundary = '----ThisIsTheBoundary1234567890'; 
     // let's encode our image file, which is contained in the var 
     var formData = '--' + boundary + '\r\n' 
     formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n'; 
     formData += 'Content-Type: ' + mimeType + '\r\n\r\n'; 
     for (var i = 0; i < imageData.length; ++i) { 
      formData += String.fromCharCode(imageData[i] & 0xff); 
     } 
     formData += '\r\n'; 
     formData += '--' + boundary + '\r\n'; 
     formData += 'Content-Disposition: form-data; name="message"\r\n\r\n'; 
     formData += message + '\r\n' 
     formData += '--' + boundary + '--\r\n'; 

     var xhr = new XMLHttpRequest(); 
     xhr.open('POST', 'https://graph.facebook.com/me/photos?access_token=' + authToken, true); 
     xhr.onload = xhr.onerror = function() { 
      console.log(xhr.responseText); 
     }; 
     xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); 
     if(!xhr.sendAsBinary){ 
      xhr.sendAsBinary = function(datastr) { 
      function byteValue(x) { 
       return x.charCodeAt(0) & 0xff; 
      } 
      var ords = Array.prototype.map.call(datastr, byteValue); 
      var ui8a = new Uint8Array(ords); 
      this.send(ui8a.buffer); 
      } 
     } 
     xhr.sendAsBinary(formData); 
     xhr.onreadystatechange = function() { 
      if (xhr.readyState == 4 && xhr.status == 200) { 
      alert('Your image has been successfully shared'); 
      } 
     } 
     }; 

     var data = yourDesigner.getProductDataURL(); 
     var encodedPng = data.substring(data.indexOf(',') + 1, data.length); 
     var decodedPng = Base64Binary.decode(encodedPng); 
     // var decodedPng = dataURItoBlob(test,"png"); 
     FB.getLoginStatus(function (response) { 
     var request = {}; 
     if (response.status === "connected") { 
      request = postImageToFacebook(response.authResponse.accessToken, "test", "image/png", decodedPng, "www.captivations.com.au"); 
     } else if (response.status === "not_authorized") { 
      FB.login(function (response) { 
      request = postImageToFacebook(response.authResponse.accessToken, "test", "image/png", decodedPng, "www.captivations.com.au"); 
      }, {scope: "publish_actions"}); 
     } else { 
      FB.login(function (response) { 
      request = postImageToFacebook(response.authResponse.accessToken, "test", "image/png", decodedPng, "www.captivations.com.au"); 
      }, {scope: "publish_actions"}); 
     } 
     }); 

私は自分のFacebookアカウントにログインして画像を投稿できます。 { 「メッセージ」::私はエラー

「エラー」以下しまった他のアカウントからの画像を投稿しようとしたときには、「(#200)、拡張権限が必要です:publish_actions」、 「タイプ」:「OAuthException 」、 "コード":200、 "fbtrace_id": "EAcb5VG/EFS" }

私はfacbookのAPIのそのアクセス許可の問題だと思います。あなたはFacebookの "公開アクション"許可の管理に私を助けることができますか? https://developers.facebook.com/docs/facebook-login/permissionsから

答えて

0

「publish_actionsは、」あなたのアプリを使用する人に代わって投稿、グラフを開くアクション、成果、スコアやその他の活動を公開するためのアクセスを提供します。

あなたのアプリは、フィードダイアログ、リクエストダイアログまたは送信ダイアログを使用するためにpublish_actions権限をリクエストする必要はありません。

別の方法で「publish_actions」権限を使用する場合は、あなたのアプリが「publish_actions」権限をどのように使用しているかを確認するようにFacebookに要求する必要があります。

+0

私は、フィードダイアログ、リクエストダイアログ、または送信ダイアログを使用していません。私はFacebookに投稿要求を送信しています。アカウントがログに記録されているが、他のアカウントからリクエストを送信するときにエラーが発生する – bittu

+0

@bittu:設定からアプリを削除してから、もう一度ログインしてください。そして今度は、ログインダイアログがあなたに示すメッセージに注意してください。 – CBroe

関連する問題