R
R
Roman2016-06-29 16:33:48
WordPress
Roman, 2016-06-29 16:33:48

Using several VK applications on the PHP API - how not to produce conditions for the type of application?

Good time!

There is an API in PHP, as well as two clients for it: a website on Angular 1.x and an iOS application. As well as two VK applications (website and standalone).
It is necessary on the API side to be able to get a list of friends, make reposts, etc., which a non-standalone application cannot do.
It is supposed to use other APIs for the same purposes: FB, Twitter, etc.
There are two sub-questions here.

The first is about organizing the storage of VK application tokens: how to organize the receipt and storage of tokens with a minimum invention of bicycles?
Situation example.The user connects VK in his personal account on our website - the API receives the VK token as a site. Then the user downloads the ios application, logs in there via VK - the API receives a second VK token, now standalone. The user on the site presses the button "create X and make a VK-repost about it."
Question: how to make this repost from the API side? Take all possible VK-tokens from the database for this user and "scientifically poke" to try everything until it works? Store the type in the database and produce two type conditions:

if ('vkontakte' == $social->getProvider()) && 'standalone' == $social->getAppType())
    $social->postOnWall($entity);

How do they generally act in such cases in practice?

The second is about libraries: which ones?
I've tried using Hybridauth, but it seems to take longer to deal with.
An example of the difficulty with it. The `authorize` method for some reason automatically sends headers with a redirect, which Angular is not able to catch - instead of just passing the access_token there and working with the entire internal social network api. Nevertheless, methods like `getUserProfile` call `isAuthorized` inside themselves, which looks for something there in php sessions - which are generally disabled in the API as unnecessary and are not used in any way (all work with data through Angular).
Question:There is an idea to add one dependency library to the project, write your own AbstractSocialAdapter and use one of these libraries depending on the situation. But I really don't want to reinvent the wheel.

Perhaps I'm doing something completely wrong? How do you solve such a problem? I would like more real examples and best practice.

Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2015-12-10
@VoxelGod

1. Pass the ID and retrieve records from the database using it.
2. Use pages and shortcodes.

E
Evgeniy, 2015-12-11
@eZhrv

You may be interested in the BuddyPress plugin:
habrahabr.ru/post/95159

Advanced Profiles - The built-in WordPress user profiles are second to none. You can include friends, groups, activity feeds, recent user posts, biography, contact information in your profile - and these are just default settings!

K
Konstantin, 2016-07-09
@unity_ultra_hardcore

1. Store the type in the database and produce two type conditions.

Yes. Store next to the token not only its expiration date, the social network from which it was obtained (in case all tokens are in the same table) and its type: website/standalone
This check can be encapsulated inside your $social:
If ($social->canPostOnWall($entity) {
    $social->postOnWall($entity);
}

I think that in the canPostOnWall method, those providers that cannot post offline should simply return false. And VK should check for the presence of a token with this user_id in the storage, with expire > now() and with type = 'standalone' and try to post a message on the wall if a suitable token was found.
Well, if I understand your architecture correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question