fix bug that would only return error responses for 3rdparty apps
logout before output to not run into header already sent problems
respect format output
Merge pull request #3216 from owncloud/fix-api-3rdparty

fix bug that would only return error responses for 3rdparty apps