3

イオンフレームワークでアプリを作成し、ログイン用にfacebookConnectPluginを統合し、ファンページに投稿しています。イオン/角型アプリでFacebookブックを作成

ログイン部分が正常に動作しているため、ユーザーデータが表示され、アプリに表示されます。私が持っている問題は、私がFacebookへの投稿をしようとするときです。

これは、ログインしてポストを管理する完全なコントローラである

.controller('signupCtrl', function($scope, $state, $q, UserService, $ionicLoading){ 
// This is the success callback from the login method 
var accesstoken; 
var fbLoginSuccess = function(response){ 
    if (!response.authResponse){ 
     fbLoginError("Cannot find the authResponse"); 
     return; 
    } 

    var authResponse = response.authResponse; 
    accesstoken = authResponse.accessToken; 

    getFacebookProfileInfo(authResponse).then(function(profileInfo){ 
     // For the purpose of this example I will store user data on local storage 
     UserService.setUser({ 
      authResponse: authResponse, 
      userID: profileInfo.id, 
      name: profileInfo.name, 
      email: profileInfo.email, 
      picture: "http://graph.facebook.com/" + authResponse.userID + "/picture?type=large" 
     }); 
     $ionicLoading.hide(); 
    }, function(fail){ 
      // Fail get profile info 
      alert('profile info fail ' + fail); 
     }); 
}; 

// This is the fail callback from the login method 
var fbLoginError = function(error){ 
    alert('fbLoginError ' + error); 
    $ionicLoading.hide(); 
}; 
    // This method is to get the user profile info from the facebook api 
var getFacebookProfileInfo = function (authResponse){ 
    var info = $q.defer(); 

    facebookConnectPlugin.api('/me?fields=email,name&access_token=' + authResponse.accessToken, null, 
     function (response) { 
      console.log(response); 
      info.resolve(response); 
     }, 
     function (response) { 
      console.log(response); 
      info.reject(response); 
     } 
    ); 
    return info.promise; 
}; 

//This method is executed when the user press the "Login with facebook" button 
$scope.facebookSignIn = function(){ 
    console.log('---> facebookSignIn'); 
    facebookConnectPlugin.getLoginStatus(function(success){ 
     if (success.status === 'connected'){ 
      // The user is logged in and has authenticated your app, and response.authResponse supplies 
      // the user's ID, a valid access token, a signed request, and the time the access token 
      // and signed request each expire 
      //alert('getLoginStatus ' + success.status); 

      // Check if we have our user saved 
      var user = UserService.getUser('facebook'); 

      if (!user.userID){ 
       alert('UNO'); 
       getFacebookProfileInfo(success.authResponse).then(function(profileInfo) { 
        // For the purpose of this example I will store user data on local storage 
        UserService.setUser({ 
         authResponse: success.authResponse, 
         userID: profileInfo.id, 
         name: profileInfo.name, 
         email: profileInfo.email, 
         picture: "http://graph.facebook.com/" + success.authResponse.userID + "/picture?type=large" 
        }); 

        //$state.go('menu.home'); 
       }, function(fail){ 
         // Fail get profile info 
         alert('profile info fail ' + fail); 
        }); 
      }else{ 
       //alert('DOS'); 
       $state.go('menu.home'); 
       var fan_token = 'EAAH1eElPgZBl1jwZCI0BADZBlrZCbsZBWF5ig29V1Sn5ABsxH1o4kboMhpjZBDfKtD1lfDK1dJLcZBI4gRBOF2XGjOmWMXD0I8jtPZA4xLJNZADarOGx8fiXBRZCTOaxwBLQEwRjsvaqTtb2DTCI0Qdo3haX6vqHlJoWMZD'; 

       console.log('access token', accesstoken); 

       facebookConnectPlugin.api(
        '/186259017448757/feed', 
        'POST', 
        { 
         access_token: fan_token, 
         'message':'HOLA!' 
        }, 
        function(response){console.log(response);alert(response.id)} 
       ) 
      } 
     }else{ 
      // If (success.status === 'not_authorized') the user is logged in to Facebook, 
      // but has not authenticated your app 
      // Else the person is not logged into Facebook, 
      // so we're not sure if they are logged into this app or not. 

      alert('getLoginStatus ' + success.status); 

      $ionicLoading.show({ 
       template: 'Logging in...' 
      }); 

      // Ask the permissions you need. You can learn more about 
      // FB permissions here: https://developers.facebook.com/docs/facebook-login/permissions/v2.4 
      facebookConnectPlugin.login(['email', 'public_profile'], fbLoginSuccess, fbLoginError); 
     } 
    }); 
}; 
}) 

これは私が私がhttps://developers.facebook.com/tools/explorerに行ってきましたFacebookの壁

facebookConnectPlugin.api('/181297057448657/feed', 'POST', {access_token: fan_token, 'message':'HOLA!'}, 
        function(response){ 
         console.log(response); 
         alert(response.id) 
        } 
       ) 

にポストを作成しようとする部分でありますアクセストークンを生成し、いくつかのトークン(ユーザー、ファンページなど)で試してみましたが、動作するようです。私も

FB.api(
    '/174801556748297/feed', 
    'POST', 
    {"message":"testing3"}, 
    function(response) { 
     // Insert your code here 
    } 
); 

をFacebookの開発者エクスプローラツールで提供されるこのコードスニペットを使用しました結果は常に同じですが、私は壁に応答オブジェクトと無Facebookの投稿でJSONのエラーを取得する

どれでも助けが本当に感謝されるだろう!

PD:アプリIDが変更されているため、一致しない理由があります。参考https://github.com/ccoenraets/sociogram-angular-ionic、私は掲示する私のアプリでは、以下の使用トークンとファンページID

+0

エラーメッセージは何を返しますか? – user2085143

+0

JSONエラー、ちょうど – Sergio

答えて

0

と同じことが

$scope.share = function() { 
     OpenFB.post('/me/feed', $scope.item) 
      .success(function() { 
       console.log("done"); 
       $ionicLoading.hide(); 
       $scope.item.message=""; 
       $ionicLoading.show({ template: 'Post successfully on Facebook!', noBackdrop: true, duration: 2000 }); 
       $scope.status = "This item has been shared from OpenFB"; 
      }) 
      .error(function(data) { 
       $ionicLoading.hide(); 
       alert(data.error.message); 
      }); 
    }; 

HTML

<div class="media-body"> 
     <textarea placeholder="What's on your mind?" ng-model="item.message"></textarea> 
    </div> 
    <hr style="margin-top: -1px;" /> 
    <div style="text-align:right;padding-right:20px;padding-bottom:10px;"> 
     <button class="fb-login" ng-click="share()">Post to Facebook</button> 
    </div> 
+0

ありがとう!それを調べます – Sergio

+0

それは私のために働いています。もしあなたのために働くなら、答えを出して、近くの問題を承認してください。ありがとう – Anuj

関連する問題