how to share on facebook within OSX app, without facebook Kit? - objective-c

I'm looking for way to use Accounts information if they configured in OS X, to post to Facebook, without using facebook kit.
I found Social framework but all examples are related to iOS, my App instead should post message from OS X.

Using accounts is a good way to go, here's what I did:
import Accounts
static func post(text:String,completion:(Bool->Void)) {
let accountStore = ACAccountStore()
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierFacebook)
let options : [String:AnyObject] = [
"ACFacebookAppIdKey": "your app key here, from Facebook apps",
"ACFacebookPermissionsKey": ["publish_actions", "manage_pages", "publish_pages"],
"ACFacebookAudienceKey": "ACFacebookAudienceEveryone"
]
accountStore.requestAccessToAccountsWithType(accountType, options: options) {
granted, error in
if granted {
let fbAccounts = accountStore.accountsWithAccountType(accountType)
if fbAccounts != nil {
completion(true)
} else {
print("no accounts")
completion(false)
}
}
}
}

Related

How to upload video to vimeo through swift

I need to upload a video file to vimeo from my ios app.
Vimeo's iOS library is deprecated, so I'm trying to upload a video using the api on the Vimeo developer site.
https://developer.vimeo.com/api/upload/videos
I'm using the resumable approach.
There are 3 steps in total. Step 1 was successful and step 2 is still failing.
Here's the method I tried in step 2:
private func uploadVideoToVimeo(uploadLink:String) {
let urlString = uploadLink
let headers: HTTPHeaders = [ "Tus-Resumable":"1.0.0",
"Upload-Offset": "0",
"Content-Type": "application/offset+octet-stream",
"Accept":"application/vnd.vimeo.*+json;version=3.4"]
var request = URLRequest(url: URL(string: urlString)!)
request.headers = headers
request.method = .patch
AF.upload(multipartFormData: { multipartFormData in
let timestamp = NSDate().timeIntervalSince1970
do {
let data = try Data(contentsOf: self.videoLocalURL, options:.mappedIfSafe)
print("data size :\(data)")
multipartFormData.append(data, withName: "\(timestamp)")
} catch {}
}, with: request).responseString { response in
switch response.result {
case .success(let data):
print("esponse :\(response)")
case let .failure(error):
print("ERROR :\(error)")
}
}
}
When I do this, the response is “missing or invalid Content-Type header”.
Any help would be greatly appreciated.
Alamofire, and Apple's network frameworks in general, don't support the TUS protocol for uploads. You either need to implement that manually and upload a stream, or switch to using the form-based approach outlined in the Vimeo docs.

Why IAP product count is empty?

I added three inapp purchases to the app and they have "Ready to submit" status.
Can I test them before submitting the application on the simulator?
I'm asking it because
response.products
are empty, when I'm using this method.
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
if response.products.count != 0 {
for product in response.products {
print(product.localizedTitle)
}
}
}
You also need to have the "Paid Applications Agreement" signed in App Store Connect before you can test products.
Also, the simulator is always sketchy for testing anything with StoreKit and I recommend testing on a physical device.

Cannot run PlusDomains example in Google App Maker

I am trying to run this example code in Google App Maker:
/**
* The following example demonstrates how to create a post that is available
* to all users within your G Suite domain.
*/
function createPost() {
var userId = 'me';
var post = {
object: {
originalContent: 'Happy Monday! #caseofthemondays'
},
access: {
items: [{
type: 'domain'
}],
domainRestricted: true
}
};
post = PlusDomains.Activities.insert(post, userId);
Logger.log('Post created with URL: %s', post.url);
}
However, I keep getting this:
GoogleJsonResponseException: Access to the Google+ Domains API is not allowed as the user has consented to incompatible scopes.
Has anybody else managed to get this working?
Pavel's link had the answer: I just had to remove all access at https://security.google.com/settings/security/permissions and then re-authorize.
Thanks, Pavel!

Login to salesforce.com with Phantomjs 2.0 keep asking for verification code

We are doing some tests to connect to the salesforce.com with Phantomjs 2.0.
It was working pretty good, but in the last couple of weeks salesforce.com kept asking for the verification code every new session.
Is anyone experiencing the same issue?
You can whitelist your IP address in order to stop Salesforce for asking the verification code.
Go to Setup -> Security -> Network Access and add your IP to whitelist.
This should perhaps be a comment, but as I do not have the required points to comment please forgive the "answer". This is a working answer, as I'm not very proficient in casper/phantom I will update on attempted solutions. Hopefully my attempts will help someone else.
Is anyone experiencing the same issue?
A: Yes
Problem: As of Salesforce Spring '16 update when logging into SF from a new browser SF authenticates the user with a verification code (can be tested with a new browser eg.firefox). Oddly the issue doesn't replicate with an incognito session.
Proposed solution: Create a cookies file & login to SF with the casper/phantom scripts. Saving the authentication to the JS cookies file, otherwise every login will require a verification.
Testing steps:
We can see the verification form using casper/phantom.
var fs = require('fs'); //top of script
var html = this.getHTML(); //place this in wait_function() after login()
fs.write('./output.html', html, 'w');
We can now "fill" the verification form with the emailed code
this.click('phSearchInput', function () { //'phSearchInput' found in above extract
this.fill('form', {
'phSearchInput' : '*verification_number_here*'
}, true);
2.1 There seems to be an issue with the final redirect after the verification. I'm not sure how much time I can give this (as it's not a priority) and I'm quite new to JS. I'll leave the code here for reference/testing
/*Altered from http://blog.deadlypenguin.com/blog/2013/07/09/logging-into-salesforce-with-casperjs/ */
var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casp;
casp = require('casper').create({
viewportSize: {
width: 1024,
height: 768
},
verbose: true,
logLevel: 'debug'
});
casp.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');
if (!casp.cli.has('username') && !casp.cli.has('password')) {
casp.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD [--prod]').exit(-1);
}
if (casp.cli.has('prod')) {
LOGIN_URL = 'https://test.salesforce.com//';
} else {
LOGIN_URL = 'https://test.salesforce.com/';
}
LOGIN_USERNAME = casp.cli.get('username');
LOGIN_PASSWORD = casp.cli.get('password');
casp.start(LOGIN_URL, function () {
this.log('Logging in', 'debug');
//login
this.fill('form', {
'username': LOGIN_USERNAME,
'pw': LOGIN_PASSWORD
}, true);
this.log('Logged in', 'debug');
});
casp.wait(5000, function () {
this.log('Varification START', 'debug');
this.fill('form', {
'emc': '*verification_number_here*'
}, true);
this.captureSelector('test.png', 'html');
this.log('Varification FINISHED', 'debug');
this.wait(6000)
}, 12000);
casp.then(function () {
//casp.waitForUrl('https://cs31.salesforce.com/home/home.jsp', function() {
this.log('Are we logged in??');
this.captureSelector('test2.png', 'html');
}, 12000);
casp.run();
Add a cookies file in hopes the verification validation is saved there. (I'll get to this when I figure out step 3).

What should I consider when I am doing an authentication process with a titanium app?

Hello it's my first time doing a sign in process in a mobile app with Titanium and I wonder what information should I save and the best practice to do it?
My server is configured in this way:
The server requires I send a user and password and if the information match it will provide a token session.
This is the code I use for signing in:
function signIn(e) {
//function to use HTTP to connect to a web server and transfer the data.
var sendit = Ti.Network.createHTTPClient({
onerror : function(e) {
Ti.API.debug(e.error);
alert('There was an error during the connection');
},
timeout : 100000,
});
//Here you have to change it for your local ip
sendit.open('POST', 'http://myserver');
var params = {
user : $.txtUsuario.value,
password : $.txtPassword.value
};
sendit.send(params);
//Function to be called upon a successful response
sendit.onload = function() {
var json = this.responseText;
var response = JSON.parse(json);
if (response.success == "true")
{
var landing = Alloy.createController("menu").getView();
$.index.close();
landing.open();
}
else
{
alert(response);
}
};
};
the code above is working, however I do not know how to manage the sign out. I would like my application works like the most apps do, e.g:
You sign in once and after that if you do not close the app you are able to continues using it and even making a request.
Thank you for any explanation.
It depends on your app requirements. for exemple if you will use the token in your app later you can save it as an AppProperty :
Ti.App.Properties.setString('token',yourTokenGoHere);
and in the app starting you can get it back :
var myToken = Ti.App.Properties.getString('token');
and then you can make a test for example if the token is still valid or not :
if(myToken === 'invalidtoken')
youSholdLogin();
else
youCanGoFurther();
and when the user disconnect rest the token to be invalid :
Ti.App.Properties.setString('token', 'invalidtoken');