1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Integrations\Connectors\Googledrive; |
4
|
|
|
|
5
|
|
|
use Log; |
6
|
|
|
use App\Models\User; |
7
|
|
|
|
8
|
|
View Code Duplication |
class Post extends Googledrive |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function send($component, $text = 'Hello word') |
17
|
|
|
{ |
18
|
|
|
try { |
19
|
|
|
// The most basic upload command, if you're sure that your photo file is |
20
|
|
|
// valid on Googledrive (that it fits all requirements), is the following: |
21
|
|
|
// $ig->timeline->uploadPhoto($photoFilename, ['caption' => $text]); |
22
|
|
|
// However, if you want to guarantee that the file is valid (correct format, |
23
|
|
|
// width, height and aspect ratio), then you can run it through our |
24
|
|
|
// automatic photo processing class. It is pretty fast, and only does any |
25
|
|
|
// work when the input file is invalid, so you may want to always use it. |
26
|
|
|
// You have nothing to worry about, since the class uses temporary files if |
27
|
|
|
// the input needs processing, and it never overwrites your original file. |
28
|
|
|
// |
29
|
|
|
// Also note that it has lots of options, so read its class documentation! |
30
|
|
|
$photo = new \GoogledriveAPI\Media\Photo\GoogledrivePhoto($component->getTarget()); |
31
|
|
|
$this->getConnection()->timeline->uploadPhoto($photo->getFile(), ['caption' => $text]); |
32
|
|
|
} catch (\Exception $e) { |
33
|
|
|
echo 'Something went wrong: '.$e->getMessage()."\n"; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getAll() |
38
|
|
|
{ |
39
|
|
|
$instagram = $this->getConnection()->likeMedia(); |
40
|
|
|
|
41
|
|
|
// set user's accesstoken (can be received after authentication) |
42
|
|
|
$instagram->setAccessToken("2823787.9687902.21u77429n3r79o08233122306fa78902"); |
43
|
|
|
|
44
|
|
|
// follow user (snoopdogg) |
45
|
|
|
$instagram->modifyRelationship('follow', $component->getReference()); |
|
|
|
|
46
|
|
|
|
47
|
|
|
// receive the list of users this user follows |
48
|
|
|
$follows = $instagram->getUserFollows(); |
49
|
|
|
|
50
|
|
|
// dump response object |
51
|
|
|
echo '<pre>'; |
52
|
|
|
print_r($follows); |
53
|
|
|
echo '<pre>'; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
$result = $this->getConnection()->likeMedia($component->getReference()); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getRelations() |
61
|
|
|
{ |
62
|
|
|
$this->getFollows(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function getFollows() |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getComments() |
71
|
|
|
{ |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.