2011-07-19 79 views
0

我試圖發佈圖像以及facebook上的鏈接。我能夠登錄獲取用戶詳細信息,但我無法發佈圖像和鏈接。以下是代碼我用使用flex在facebook上發佈圖像

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" width="600" height="300" 
      creationComplete="initApp()"> 
<s:states> 
    <s:State name="loggedout"/> 
    <s:State name="loggedin"/> 
</s:states> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<fx:Script> 
    <![CDATA[ 
     import com.facebook.graph.Facebook; 
     import com.facebook.graph.controls.Distractor; 

     protected function initApp():void 
     { 
      Facebook.init("XXXX",loginHandler); 
     } 
     protected function loginHandler(success:Object,fail:Object):void 
     { 
      if(success){  
       currentState="loggedin"; 
       Facebook.api("/me",getMeHandler); 
       userImg.source=Facebook.getImageUrl(success.uid,"small"); 
       Facebook.api("/me/statuses",getStatusHandler); 
      } 
     } 
     protected function login():void 
     { 
      Facebook.login(loginHandler, {perms:"user_birthday,read_stream,publish_stream"}); 

     } 
     protected function getMeHandler(result:Object,fail:Object):void{ 
      nameLbl.text=result.name; 
      birthdayLbl.text=result.birthday; 
     } 
     protected function logout():void 
     { 
      Facebook.logout(logoutHandler); 
      currentState="loggedout"; 
     } 
     protected function getStatusHandler(result:Object, fail:Object):void 
     { 
      statusLbl.text=result[0].message; 
     } 
     protected function submitPost():void 
     { 
      var obj:Object = new Object(); 
      obj.message = statusInput.text; 
      obj.link = "url of the image stored on the server"; 
      obj.type ='link'; 
      Facebook.api("/me/feed",submitPostHandler,obj, "POST"); 

     } 
     protected function submitPostHandler(result:Object,fail:Object):void 
     { 
      statusInput.text=""; 
      Facebook.api("/me/statuses",getStatusHandler); 
     } 
     protected function logoutHandler(response:Object):void{ 

     } 

    ]]> 
</fx:Script> 

<s:Button label="Log in" includeIn="loggedout" right="10" top="10" click="login()" skinClass="skins.FBLoginButtonSkin"/> 
<s:Button includeIn="loggedin" label="Log out" right="10" top="10" click="logout()" skinClass="skins.FBLogoutButtonSkin"/> 
<mx:Form includeIn="loggedin" top="10" left="70"> 
    <mx:FormItem label="User"> 
     <s:Label id="nameLbl"/> 
    </mx:FormItem> 
    <mx:FormItem label="Birthday"> 
     <s:Label id="birthdayLbl"/> 
    </mx:FormItem> 
    <mx:FormItem label="Status"> 
     <s:Label id="statusLbl"/> 
    </mx:FormItem> 
    <mx:FormItem label="Post status" direction="horizontal"> 
     <s:TextInput id="statusInput"/> 
     <s:Button label="Submit" click="submitPost()"/> 
    </mx:FormItem>  
</mx:Form> 
<mx:Image includeIn="loggedin" id="userImg" top="10" width="50" left="10"/> 

的圖像存儲在公共server.Can有人點我在哪裏,我要去錯了???

回答

0

我真的不知道這行:對空氣

Facebook.login(loginHandler, {perms:"user_birthday,read_stream,publish_stream"}); 

我使用:

Facebook.login(loginHandler, ['email', 'user_birthday', 'read_stream', 'publish_stream']); 

當您允許應用程序使用你的數據,你看它像這個?

enter image description here

UPDATE

嘗試這樣的:

private function submitPost():void { 
     var params:Object = 
     { 
      message:'My test post of the image', 
      picture:'http://actual.path.to.the.jpg', 
      link:'', 
      name:'', 
      caption:'', 
      description:'description about image', 
      source:''; 
     }; 

     FacebookDesktop.api('/me/feed', submitPostHandler, params, "POST");    
    }; 

閱讀更多關於它在這裏:

https://developers.facebook.com/docs/reference/api/#publishing

這裏:

https://developers.facebook.com/docs/reference/api/post/

+0

Hi..the語法correct..I我能夠查看權限盒以及後期的wall.The問題是圖像(obj.link)沒有被顯示在牆... – newbie

+0

更新的答案與更多信息。 –

+0

嘿謝謝:)它的工作..從mysideSilly錯誤... – newbie