Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1233] FB Login and Sharing not working proper.

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2015-09-15T04:05:00.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsTCSupportTriage, api, ios
Reportershubham mishra
AssigneeShak Hossain
Created2014-08-20T09:36:18.000+0000
Updated2016-03-08T07:37:37.000+0000

Description

I am working in facebook sharing using graph API but during develoment I'm facing following issues: 1. Login event listener not callback but user has logged In at first time. 2. In Second time some time facebook sharing working but next time it's giving me error which I've attached screenshot for the same. most of the time sharing done in first time but second time it's giving me error. Below are the code which I'm using. Also I've added "xxxxxxxxxxxxxxxxx" in .xml and info.plist with key. Please provide me any solution: var data = { message:'Post Sharing' }; function showFBResult(eventData) { if (eventData.success) { alert('in succes'); } else { if (eventData.error) { alert(eventData.error); } } } var fb = require('facebook'); fb.appid = "xxxxxxxxxxxxxxxx"; fb.permissions = ['publish_stream']; fb.forceDialogAuth = true; if (!fb.loggedIn) { fb.authorize(); }else{ fb.requestWithGraphPath('me/feed', data, 'POST', showFBResult); } fb.addEventListener('login', function(e){ if(e.success){ fb.requestWithGraphPath('me/feed', data, 'POST', showFBResult); } else if (e.error) { alert(e.error); } });

Attachments

FileDateSize
screen1.png2014-08-20T09:36:18.000+000037798

Comments

  1. Motiur Rahman 2015-08-19

    Hello, On latest Ti SDK version FB login and sharing is working as expected. Please try the following code with the latest version of the SDK *Testing Environment:* Command-Line Interface, version 4.1.2, FB Module Version: 4.0.5, Ti SDK: 4.1.0, iOS Version: v8.4, Studio Version: 4.1.1 *Test Code*
       var win = Ti.UI.createWindow({
       	backgroundColor : 'white',
       	layout : 'vertical'
       });
       
       var share = Ti.UI.createButton({
       	title : 'Share',
       	height : 100,
       	width : 100,
       	top : 100,
       	color : '#000'
       });
       
       // Listen for click events.
       share.addEventListener('click', function() {
       	shareData();
       });
       
       win.add(share);
       
       var fb = require('facebook');
       fb.appid = "APP_ID";
       
       fb.addEventListener('login', function(e) {
       	if (e.success) {
       		alert('Logged in');
       
       	}
       });
       fb.addEventListener('logout', function(e) {
       	alert('Logged out');
       });
       
       win.add(fb.createLoginButton({
       	top : 50,
       	style : fb.BUTTON_STYLE_WIDE
       }));
       
       var data = {
       	message : "Trying out FB Graph API and it's fun!"
       };
       
       function shareData() {
       	fb.requestNewPublishPermissions(['publish_actions'], fb.AUDIENCE_FRIENDS, function(e) {
       		if (e.success) {
       			fb.requestWithGraphPath('me/feed', data, "POST", function(e) {
       				if (e.success) {
       					alert("Success!  From FB: " + e.result);
       				} else {
       					if (e.error) {
       						alert(e.error);
       					} else {
       						alert("Unkown result");
       					}
       				}
       			});
       		} else {
       			Ti.API.debug('Failed authorization due to: ' + e.error);
       		}
       	});
       
       }
       
       win.open();
       
       
        <ti:app>
               <ios>
                   <plist>
                       <dict>
                           <key>CFBundleURLTypes</key>
                           <array>
                               <dict>
                                   <key>CFBundleURLName</key>
                                   <!-- Application ID same as the id value in the tiapp.xml file -->
                                   <string>APP_ID</string>
                                   <key>CFBundleURLSchemes</key>
                                   <array>
                                       <!-- Prefix the Facebook App ID with 'fb' -->
                                       <string>fbFACEBOOK_APP_ID</string>
                                   </array>
                               </dict>
                           </array>
                           <key>FacebookAppID</key>
                           <!-- Facebook App ID -->
                           <string>FACEBOOK_APP_ID</string>
                           <key>FacebookDisplayName</key>
                           <!-- Facebook App Name from developer.facebook.com -->
                           <string>FACEBOOK_APP_NAME</string>
                       </dict>
                   </plist>
               </ios>
           </ti:app>
       
    Thanks.

JSON Source